note 57319 deleted from function.array-multisort by cmb
| From: | cmb@php.net | Date: | Sun, 29 Sep 2019 07:44:55 +0000 |
| Subject: | note 57319 deleted from function.array-multisort by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212416@lists.php.net to get a copy of this message | ||
Note Submitter: Shmee
----
RWCs code works very well until you get a point value greater then ten. This is because the
strcmp() function will return that 2 > 10 and 2 > 11
2 > 19 and so on. To compare number
values over ten try a sort like this:
$test = multi_sort($test, $key = 'points');
function multi_sort($array, $akey)
{
function compare($a, $b)
{
global $key;
if ($a[$key]>$b[$key]){
$varcmp = "1";
return $varcmp;
}
elseif ($a[$key]<$b[$key]){
$varcmp = "-1";
return $varcmp;
}
elseif ($a[$key]==$b[$key]){
$varcmp = "0";
return $varcmp;
}
}
usort($array, "compare");
return $array;
}