note 100325 deleted from function.uasort by cmb
| From: | cmb@php.net | Date: | Wed, 22 Jun 2016 17:24:55 +0000 |
| Subject: | note 100325 deleted from function.uasort by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-205783@lists.php.net to get a copy of this message | ||
Note Submitter: Yves
----
Took me some time to figure that out:
the user function must return an *integer*, if you return a float, you may not get the expected
result.
<?php
$a = ('a' => 0.9, 'b' => 0.7, 'c' => 0.8);
function sorting($a, $b) { return $a - $b; }
// The function above will not =work, you have to
function sorting($a, $b)
{
$d = $a = $b;
return $d < 0 ? -1 : ($d > 0 ? 1 : 0);
}
?>