note 92285 added to function.usort
| From: | maarten at xel dot nl | Date: | Fri, 17 Jul 2009 15:45:46 +0000 |
| Subject: | note 92285 added to function.usort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158420@lists.php.net to get a copy of this message | ||
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:
function naturalSortObjectArray($objectArray) {
function naturalSortByName($a, $b) {
return strnatcmp($a->name, $b->name);
}
usort($objectArray, "naturalSortByName");
return $objectArray;
}
----
Server IP: 64.71.164.2
Probable Submitter: 85.147.244.246
----
Manual Page -- http://www.php.net/manual/en/function.usort.php
Edit -- https://master.php.net/note/edit/92285
Del: integrated -- https://master.php.net/note/delete/92285/integrated
Del: useless -- https://master.php.net/note/delete/92285/useless
Del: bad code -- https://master.php.net/note/delete/92285/bad+code
Del: spam -- https://master.php.net/note/delete/92285/spam
Del: non-english -- https://master.php.net/note/delete/92285/non-english
Del: in docs -- https://master.php.net/note/delete/92285/in+docs
Del: other reasons-- https://master.php.net/note/delete/92285
Reject -- https://master.php.net/note/reject/92285
Search -- https://master.php.net/manage/user-notes.php