note 123127 deleted from array.sorting by cmb
| From: | cmb@php.net | Date: | Sun, 05 Jan 2020 08:54:40 +0000 |
| Subject: | note 123127 deleted from array.sorting by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213789@lists.php.net to get a copy of this message | ||
Note Submitter: luca at lauretta dot info
----
If you're looking for a quick solution to make usort stable, you could use uksort like in the
following example:
<?php
uksort($array, function ($ak, $bk) use ($array) {
$a = $array[$ak];
$b = $array[$bk];
if ($a['foo'] === $b['foo']) return $ak - $bk;
return $a['foo'] > $b['foo'] ? 1 : -1;
});
?>
This works as expected only if the initial indices (keys) of $array are in ascending order.