Trying to sort an array below memnum in ascending order, and I'm a little confused, which is better to use ... usort or array_multisort? I thought that it is multidimensional? Does anyone have an example of this?
Array ( [0] => Array ( [memnum] => 3236467423 [mid] => 1104881300 [fname] => JOHN [lname] => DOE [add1] => OMITTED [add2] => [city] => CHESTERFIELD [state] => MI [zip] => 48051 [age] => 50 ) [1] => Array ( [memnum] => 3258467922 [mid] => 1105121457 [fname] => JANE [lname] => DOE [add1] => OMITTED [add2] => [city] => CHESTERFIELD [state] => MI [zip] => 48051 [age] => 50 ) [2] => Array ( [memnum] => 3237769108 [mid] => 1104489312 [fname] => BOB [lname] => DOE [add1] => OMITTED [add2] => [city] => CHESTERFIELD [state] => MI [zip] => 48051 [age] => 50 ) )
Just usort:
usort
usort($arr, function (array $a, array $b) { return $a["memnum"] - $b["memnum"]; });
array_multisortIt is used to simultaneously compare elements from different arrays (or submatrices). You want to compare the elements of only one array, so you are using usort. The fact that these elements themselves are arrays does not matter.
array_multisort
Google array_multisort usort, , 4 .
usort() array_multisort(). ( , array_multisort.)
, 20 000 10 000 , usort() 7-15 , array_multisort(), int, . , , php .
, , 30-35% usort() . , 8 , 10 . , , . array_column() pre-5.5 .