April 3rd, 2013, 08:16 PM
How to sort multi-dimentional array in PHP
Is it possible to sort this array based on the total?
April 3rd, 2013, 08:46 PM
Certainly it's possible. You can use array_multisort or usort. The documentation page for array_multisort has an example of sorting 2-dimension arrays.
April 3rd, 2013, 08:48 PM
Use usort with a function that takes two of those subarrays and returns which comes first. Check the manual page and user comments for some examples how.
April 3rd, 2013, 10:52 PM
Thanks this works fine.
foreach($lookup as $val =>$row)
$sorted[$val] = $row['total'];
array_multisort($sorted, SORT_ASC, $lookup);