I have a use for ksort()
and I need to choose the sorting order(ASC/DESC).
Is there a way of doing it without array_multisort()
?
The ksort() function sorts an associative array in ascending order, according to the key. Tip: Use the krsort() function to sort an associative array in descending order, according to the key. Tip: Use the asort() function to sort an associative array in ascending order, according to the value.
The array_multisort() function returns a sorted array. You can assign one or more arrays. The function sorts the first array, and the other arrays follow, then, if two or more values are the same, it sorts the next array, and so on.
Sorting associative arrays can be done in one of several ways: Sort by keys, leave key-value association intact: Use ksort(). Sort by keys in reverse order, leave key-value association intact: Use krsort(). Sort by values, leave key-value association intact: Use asort().
rsort() - sort arrays in descending order. asort() - sort associative arrays in ascending order, according to the value. ksort() - sort associative arrays in ascending order, according to the key. arsort() - sort associative arrays in descending order, according to the value.
krsort()
for descending orderksort()
for ascending order
Also :
krsort()
function to sort an associative array in descending order, according to the key.
&
ksort
for ascending order
plus
arsort()
function to sort an associative array in ascending order, according to the value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With