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?
✗ Incorrect
asort() sorts values ascending and keeps keys unchanged.What happens to keys when you use
sort() on an array?✗ Incorrect
sort() reindexes keys starting from 0 after sorting.Which function sorts an array by keys in descending order?
✗ Incorrect
krsort() sorts keys descending, preserving key-value pairs.If you want to sort an array by values in descending order and keep keys, which function do you use?
✗ Incorrect
arsort() sorts values descending and preserves keys.Which function would you use to sort an array by keys in ascending order?
✗ Incorrect
ksort() sorts keys ascending, preserving key-value pairs.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.