Re: Sorting array of objects

From: Date: Mon, 05 Apr 2004 18:35:01 +0000
Subject: Re: Sorting array of objects
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-182388@lists.php.net to get a copy of this message
Richard Harb wrote:
Hi there, Supposed I have an array of objects, like: $this[$i]->property1 $this[$i]->property2 is there any 'cheap' way to sort the array according to the values of property1?
http://www.php.net/usort Example: function cmp($a, $b) { if ($a->property1 == $b->property1) {
       return 0;
} return ($a->property1 < $b->property1) ? -1 : 1; } usort($object_array, "cmp");

« previous php.general (#182388) next »