Sort an array of objects in PHP by field

function cmp($a, $b)
    return strcmp($a->name, $b->name);

usort($your_data, "cmp");

Or the shorter version using closures:

usort($your_data, function($a, $b)
    return strcmp($a->name, $b->name);

Ref :

You might also like

Expose config.yml values globally for Twig templates in Symfony2 applications
Lets suppose you have created a bundle that has some specific configuration in the config.yml file (this...
Symfony2 – ErrorException: Notice: serialize() [function.serialize]: “xxx” returned as member variable from __sleep() but does not exist in …
While storing an entity from Doctrine2 in the session under a Symfony2 application I got this error: ErrorException:...
Using the Xcode Simulator with a Unity 3 Native iOS Plug-In
As you saw in "Building a Unity 3 Application with Native Plugin for iOS" we can create a plug in for...
Install and configure MongoDB and PHP driver with MacPorts
Installing and configuring MongoDB with MacPorts Installing MongoDB with MacPorts is as easy as...
Leave a comment ?


Leave a Comment