note 117659 deleted from function.usort by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 16:34:36 +0000 |
| Subject: | note 117659 deleted from function.usort by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217837@lists.php.net to get a copy of this message | ||
Note Submitter: me at evertpot dot com
----
I see many people here (including the official examples) write their callbacks rather clumsily like
this:
<?php
function($a, $b) {
if ($a === $b) {
return 0;
} elseif ($a < $b) {
return -1;
} else {
return 1;
}
}
?>
Or if they are a bit more clever:
<?php
function($a, $b) {
if ($a === $b) {
return 0;
} else {
return $a < $b ? -1 : 1;
}
}
?>
But this can by simplified further to:
<?php
function($a, $b) {
return $a - $b;
}
?>