note 92285 modified in function.usort by danbrown

From: Date: Fri, 17 Jul 2009 15:46:37 +0000
Subject: note 92285 modified in function.usort by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158421@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: <?php function naturalSortObjectArray($objectArray) { function naturalSortByName($a, $b) { return strnatcmp($a->name, $b->name); } usort($objectArray, "naturalSortByName"); return $objectArray; } ?> --was-- 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; } http://php.net/manual/en/function.usort.php

« previous php.notes (#158421) next »