usort for sorting an array of objects

From: Date: Wed, 10 Dec 2008 04:15:55 +0000
Subject: usort for sorting an array of objects
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-284400@lists.php.net to get a copy of this message
Hi Guys, I need to sort an array of objects. I found this ( at a url that didnt let me send this msg... ) and I would know how to do it, but I believe there might be a cleaner, more elegant way to do it. In Java, you just need to implement the interface Comparable and provide a method called compareTo (as far as i remember) and then you can use one of the many sorting algorithms generically on objects that are comparable... Anyway, I didn't find something like that for PHP. Since I'm using symfony, I had a bit of a play with the objects at hand and simply did a sort($arrayOfObjects) and it did sort them by the id. Just wondering where it got the information on what to sort on (not quite) correctly for my case? Thanks for your interest. -- Tim-Hinnerk Heuer http://www.ihostnz.com -- Web Design, Hosting and free Linux Support

« previous php.general (#284400) next »