I have this stdclass object array
Array
(
[0] => stdClass Object
(
[id] => 3
[message] => c
)
[1] => stdClass Object
(
[id] => 2
[message] => b
)
[2] => stdClass Object
(
[id] => 1
[message] => a
)
[3] => stdClass Object
(
[id] => 4
[message] => d
)
)
but I need to sort this with respect to their id values ....
PHP provides the usort
function for this: usort documentation
$sortedArray = usort($array, function($a, $b) {
return $a->id - $b->id;
});