Re: Sorting array of objects
| From: | Rob Ellis | Date: | Mon, 05 Apr 2004 13:04:22 +0000 |
| Subject: | Re: Sorting array of objects | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-182358@lists.php.net to get a copy of this message | ||
On Mon, Apr 05, 2004 at 05:03:17AM +0200, 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?
>
Try array_multisort() ->
// create a temporary array of just the property
// you want to sort on...
foreach ($array_of_objects as $k => $o)
$temp[$k] = $o->property1;
// sort
array_multisort($temp, $array_of_objects);
- Rob