zander1983 Posted October 24, 2011 Share Posted October 24, 2011 I have an array and when i do a print_r(), i get this: Array ( [0] => Array ( [path] => 1 [order] => 2 ) [1] => Array ( [path] => 2 [order] => 2 ) [2] => Array ( [path] => 3 [order] => 1 ) ) I want to sort it so that the array with an order of 1 is at the front, i.e. that last array in this case. I tried asort but that didnt do anything... Link to comment https://forums.phpfreaks.com/topic/249730-sorting-mulidimensional-array-by-value/ Share on other sites More sharing options...
zander1983 Posted October 24, 2011 Author Share Posted October 24, 2011 got it, i used this: <?php // Sort the multidimensional array usort($results, "custom_sort"); // Define the custom sort function function custom_sort($a,$b) { return $a['some_sub_var']>$b['some_sub_var']; } ?> Link to comment https://forums.phpfreaks.com/topic/249730-sorting-mulidimensional-array-by-value/#findComment-1281847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.