|
Posted by ZeldorBlat on 09/19/06 18:58
Moti.Ba@gmail.com wrote:
> Hello,
>
> I have a class like this one
>
> Class foo
> {
> public $sum;
> }
>
> And I have an array of instances based on this class. When I use
> ksort() the array is sorted by key, next I want to sort it by the $sum
> property.
>
> How can I do it?
Try usort():
<http://www.php.net/usort>
Something like this should work:
function cmpFoo($a, $b)
{
if ($a->sum == $b->sum)
return 0;
return ($a->sum < $b->sum) ? -1 : 1;
}
usort($arr, "cmpFoo"); //$arr is the array of objects
Navigation:
[Reply to this message]
|