|
Posted by Greg D on 12/13/06 15:27
"Michael Fesser" <netizen@gmx.de> wrote in message
news:niiun2tqj9n2rhhf4meql2e95oau2vinis@4ax.com...
> .oO(Greg D)
>
>>I'm trying to sort an array of objects within an object. Included is a
>>dumbed down example so that we can get at the meat of the issue without
>>worrying about complexity or validation. Basically, Funk is an object
>>that
>>has a name (string) and a value(int). FunkThis represents an object
>>containing a list of Funks, with each key corresponding to the name of the
>>Funk. I want to sort this list by val, but I get a Warning: usort():
>>Invalid comparison function error when I run the script. Keep in mind
>>that
>>this is for PHP 4
>>[...]
>
> callback
> http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback
>
> | A method of an instantiated object is passed as an array containing an
> | object as the element with index 0 and a method name as the element
> | with index 1.
>
> Since compareFunks() is a method of FunkThis, you need
>
> uasort($list, array($this, 'compareFunks'));
>
> to call it.
Ah, see, I had done that, and when invoking FunkThis->compareFunks(), it
printed 1.
I then used uasort($this->list, array($this, 'compareFunks'));
and it worked fine. Must be because the function parameter is passing the
array by reference.
Thanks!
Greg
[Back to original message]
|