Jump to content

sort array


dreamwest

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.