Bird
0
0

Which PHP function correctly sorts the array $arr in ascending order?

easy📝 Syntax Q3 of 15
PHP - Array Functions
Which PHP function correctly sorts the array $arr in ascending order?
Arsort($arr);
Basort($arr);
Cksort($arr);
Dsort($arr);
Step-by-Step Solution
Solution:
  1. Step 1: Understand sorting functions

    sort() sorts array values in ascending order and reindexes keys.
  2. Step 2: Differentiate other functions

    asort() sorts while preserving keys, ksort() sorts by keys, and rsort() sorts in descending order.
  3. Final Answer:

    sort($arr); -> Option D
  4. Quick Check:

    sort() sorts values ascending [OK]
Quick Trick: sort() sorts values ascending and reindexes keys [OK]
Common Mistakes:
  • Confusing asort() with sort()
  • Using rsort() which sorts descending

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes