unknownsheep Posted February 13, 2008 Share Posted February 13, 2008 Hello. I have an array much like this one. array(3) { [0]=> array(3) { [0]=> string(2) "11" [1]=> string(2) "10" [2]=> string(3) "abc" } [1]=> array(3) { [0]=> string(3) "130" [1]=> string(3) "243" [2]=> string(3) "foo" } [2]=> array(3) { [0]=> string(2) "76" [1]=> string(3) "107" [2]=> string(6) "qwerty" } } I want to sort it so that the inner array with the highest value in the first key [ 0 ] comes first and so on.. In this case $array[1][0] is the biggest. Its quite hard to explain but it would result in: array(3) { [0]=> array(3) { [0]=> string(3) "130" [1]=> string(3) "243" [2]=> string(3) "foo" } [1]=> array(3) { [0]=> string(2) "76" [1]=> string(3) "107" [2]=> string(6) "qwerty" } [2]=> array(3) { [0]=> string(2) "11" [1]=> string(2) "10" [2]=> string(3) "abc" } } Quote Link to comment https://forums.phpfreaks.com/topic/90872-sort-multi-dimensional-arrays/ Share on other sites More sharing options...
sasa Posted February 13, 2008 Share Posted February 13, 2008 try <?php $a = array( array("11" , "10", "abc"), array("130", "243", "foo"), array("76" , "107", "qwerty")); rsort($a); print_r($a); ?> Quote Link to comment https://forums.phpfreaks.com/topic/90872-sort-multi-dimensional-arrays/#findComment-465872 Share on other sites More sharing options...
unknownsheep Posted February 13, 2008 Author Share Posted February 13, 2008 Oh, that simple. I'm sure i tried that.. oh well, works now. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/90872-sort-multi-dimensional-arrays/#findComment-466380 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.