fevangelou
1/30/2015 - 6:23 PM

Sort array of objects in PHP

Sort array of objects in PHP

// Typical method
function cmp($a, $b)
{
    return strcmp($a->name, $b->name);
}

usort($your_data, "cmp");

// For PHP 5.3+ (using closures)
usort($your_data, function($a, $b){
    return strcmp($a->name, $b->name);
});