note 92285 deleted from function.usort by cmb
| From: | cmb@php.net | Date: | Sun, 13 Oct 2019 08:15:55 +0000 |
| Subject: | note 92285 deleted from function.usort by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212634@lists.php.net to get a copy of this message | ||
Note Submitter: maarten at xel dot nl
----
If you ever have to sort a collection of objects on something like a string (name) present in every
object, but want to keep the array of objects intact you might find this useful:
<?php
function naturalSortObjectArray($objectArray) {
function naturalSortByName($a, $b) {
return strnatcmp($a->name, $b->name);
}
usort($objectArray, "naturalSortByName");
return $objectArray;
}
?>