我有这个stdclass对象数组
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
)
)
但我需要根据他们的id值对此进行排序....
答案 0 :(得分:1)
PHP为此提供了usort
函数:usort documentation
$sortedArray = usort($array, function($a, $b) {
return $a->id - $b->id;
});