dreamwest Posted March 7, 2011 Share Posted March 7, 2011 Why does krsort return the array as "1"? $m = array('34' => 1122, '6' => 1944, '9' => 1710); print_r($m); //outputs: Array ( [34] => 1122 [6] => 1944 [9] => 1710 ) print_r(krsort($m)); //outputs: 1 What i need is the output to be Array ( [6] => 1944 [9] => 1710 [34] => 1122) Quote Link to comment https://forums.phpfreaks.com/topic/229848-sort-array/ Share on other sites More sharing options...
kenrbnsn Posted March 7, 2011 Share Posted March 7, 2011 The function krsort() returns a boolean, not an array. You want to do <?php $m = array('34' => 1122, '6' => 1944, '9' => 1710); print_r($m); //outputs: Array ( [34] => 1122 [6] => 1944 [9] => 1710 ) krsort($m); echo '<pre>' . print_r($m,true) . '</pre>'; //formats the print_r better ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/229848-sort-array/#findComment-1183876 Share on other sites More sharing options...
dreamwest Posted March 7, 2011 Author Share Posted March 7, 2011 Sweet thanks! Quote Link to comment https://forums.phpfreaks.com/topic/229848-sort-array/#findComment-1183878 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.