How can I sort this array of objects by one of its fields, like name or count ?
Array
(
[0] => stdClass Object
(
If you want to sort integer values:
// Desc sort
usort($array,function($first,$second){
return $first->number < $second->number;
});
// Asc sort
usort($array,function($first,$second){
return $first->number > $second->number;
});
UPDATED with the string don't forget to convert to the same register (upper or lower)
// Desc sort
usort($array,function($first,$second){
return strtolower($first->text) < strtolower($second->text);
});
// Asc sort
usort($array,function($first,$second){
return strtolower($first->text) > strtolower($second->text);
});