thiggins09 Posted July 28, 2007 Share Posted July 28, 2007 What is the most efficient way to do this for a fairly big array? For example: $arr[0][0]='apple'; $arr[0][1]='24'; $arr[1][0]='orange'; $arr[1][1]='2'; $arr[2][0]='banana'; $arr[2][1]='3451'; What would be the best way to sort that array by the inner array's 1 key? Link to comment https://forums.phpfreaks.com/topic/62119-solved-sorting-2d-array-by-inner-arrays-key/ Share on other sites More sharing options...
tibberous Posted July 28, 2007 Share Posted July 28, 2007 $arr[0][0]='apple'; $arr[0][1]='24'; $arr[1][0]='orange'; $arr[1][1]='2'; $arr[2][0]='banana'; $arr[2][1]='3451'; function compare($ar1, $ar2){ return ($ar1[1] > $ar2[1]); } uksort($arr, "compare"); foreach($arr as $sub){ echo "$sub[0], $sub[1]<br>"; } What is that, your homework problem? Link to comment https://forums.phpfreaks.com/topic/62119-solved-sorting-2d-array-by-inner-arrays-key/#findComment-309277 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.