How can I sort this array of objects by one of its fields, like name
or count
?
Array
(
[0] => stdClass Object
(
If you need local based string comparison, you can use strcoll instead of strcmp
.
Remeber to first use setlocale with LC_COLLATE
to set locale information if needed.
usort($your_data,function($a,$b){
setlocale (LC_COLLATE, 'pl_PL.UTF-8'); // Example of Polish language collation
return strcoll($a->name,$b->name);
});