Is there a way to choose the sorting of ksort?
Asked Answered
S

2

42

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()?

Slut answered 27/11, 2013 at 0:47 Comment(1)
After ksort try array_reverseAgnosia
B
107

krsort() for descending order
ksort() for ascending order

Brocklin answered 27/11, 2013 at 0:50 Comment(2)
So why does it let you use the SORT_DESC flag?? So happy I found this answer - thanks!Larkspur
php.net/manual/en/array.sorting.php has a very useful comparison of all the built-in sorting functions.Euraeurasia
C
7

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.

Cattalo answered 12/5, 2015 at 17:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.