note 126198 deleted from function.usort by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 16:43:08 +0000 |
| Subject: | note 126198 deleted from function.usort by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217839@lists.php.net to get a copy of this message | ||
Note Submitter: jab_creations at yahoo dot com
----
The usort function should not be used for associative arrays where the base keys need to retain
their names, otherwise this:
$a = array('example' => 'hello');
Will be converted to:
$a = array(0 => 'hello');
To retain key names in associative arrays you can simply replace usort with uasort; for me it was a
drop-in replacement without having to change anything else.