Sorting a multidimensional array by row?

I need to sort this array by ascending subdirectory "description". I tried several methods like usort, ksort, subval_sort, but none of them work (I think the main problem is that these are strings, always)

Any help is appreciated

array(77) { [0]=> array(3) { ["name"]=> string(17) "abcd" ["description"]=> string(15) "Delete XY" ["level"]=> int(1) } [1]=> array(3) { ["name"]=> string(13) "fgfgdgfd" ["description"]=> string(18) "Uploader XY" ["level"]=> int(1) } [2]=> array(3) { ["name"]=> string(15) "sdfdsfsdfs" ["description"]=> string(20) "Download abc" ["level"]=> int(0) } } 
+6
source share
2 answers
 usort($array, function ($a, $b) { return strcasecmp($a['description'], $b['description']); //compare two strings ignoring case }); 
+10
source

you can use the SORT_STRING option array_multisort as:

 array_multisort($ar[0], SORT_ASC, SORT_STRING, $ar[1], , SORT_ASC, SORT_STRING); 
0
source

Source: https://habr.com/ru/post/910478/


All Articles