Re: usort for sorting an array of objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You can use a (base) object Comparable with a method compareTo as the callback function for http://php.net/usort

That gives you 99% of what you want, for the tiny price of having to pass in the array('Comparable','compareTo') as the callback arg.

Given that one frequently calls usort and friends on arrays of data that are NOT objects at all, and, arguably, even on arrays of disparate objects or objects and non-objects, what would you expect to happen?

usort(array(new Foo, new Bar, 42, new Baz, 'expected outcome?'));

Assume Foo, Bar, and Baz all have different/unique incompatible compareTo methods.

PHP is not Java.

Trying to force it to do things the Java way means you probably need to spend more time understanding the preceding sentence.

:-)


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux