0
0
PHPprogramming~5 mins

Array sort functions in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the sort() function do in PHP?
The sort() function sorts an array in ascending order and reindexes the keys starting from 0.
Click to reveal answer
beginner
How does asort() differ from sort()?
asort() sorts an array in ascending order but preserves the original keys, unlike sort() which reindexes keys.
Click to reveal answer
beginner
What is the purpose of ksort() in PHP?
ksort() sorts an array by its keys in ascending order, keeping the key-value association intact.
Click to reveal answer
intermediate
Explain the difference between rsort() and arsort().
rsort() sorts an array in descending order and reindexes keys, while arsort() sorts in descending order but preserves the original keys.
Click to reveal answer
intermediate
What does krsort() do?
krsort() sorts an array by its keys in descending order, preserving key-value pairs.
Click to reveal answer
Which PHP function sorts an array by values in ascending order and preserves keys?
Aksort()
Bsort()
Casort()
Drsort()
What happens to keys when you use sort() on an array?
AKeys are preserved
BKeys are sorted
CKeys are removed
DKeys are reindexed starting from 0
Which function sorts an array by keys in descending order?
Akrsort()
Bksort()
Carsort()
Drsort()
If you want to sort an array by values in descending order and keep keys, which function do you use?
Arsort()
Barsort()
Csort()
Dasort()
Which function would you use to sort an array by keys in ascending order?
Aksort()
Basort()
Csort()
Darsort()
Describe the difference between sort() and asort() in PHP.
Think about what happens to the keys after sorting.
You got /3 concepts.
    Explain when you would use ksort() versus sort().
    Consider whether you want to sort by keys or values.
    You got /4 concepts.