Bird
0
0

Which PHP function sorts an array by its values in ascending order and resets the array keys to numerical indices starting from zero?

easy📝 Conceptual Q1 of 15
PHP - Arrays
Which PHP function sorts an array by its values in ascending order and resets the array keys to numerical indices starting from zero?
Asort()
Basort()
Cksort()
Darsort()
Step-by-Step Solution
Solution:
  1. Step 1: Understand the function behavior

    sort() sorts the array by values in ascending order and reindexes keys numerically starting from 0.
  2. Step 2: Compare with other functions

    asort() sorts by values but preserves keys; ksort() sorts by keys; arsort() sorts by values descending.
  3. Final Answer:

    sort() -> Option A
  4. Quick Check:

    sort() resets keys after sorting [OK]
Quick Trick: sort() reindexes keys, asort() preserves keys [OK]
Common Mistakes:
  • Confusing asort() with sort() regarding key preservation
  • Thinking ksort() sorts by values
  • Assuming arsort() sorts ascending

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes