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) 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 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! Link to comment https://forums.phpfreaks.com/topic/229848-sort-array/#findComment-1183878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.