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? Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.