尝试对对象中存在的数组进行排序,但出现错误usort() 期望参数 1 为数组我在任何地方都没有找到此错误的任何有用的解决方案,如何按数组元素总数对数组[详细信息]进行排序。
这是我的代码 -
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $manager->executeQuery("DB.col", $query);
foreach($cursor as $row) {
foreach($row->detail as $item) {
function cmp($a, $b) {
return $a['detail'] > $b['detail'];
}
usort($row, "cmp");
}
}
我的数组的架构:
array(
[0]=>stdclass object(
[_id] => MongoDB\BSON\ObjectId Object (
[oid] => 5f55f95815a8508e2deac8dd
)
[Date] => 9/12/2020
[title] => ram
[roll.n] => 5
[detail] => Array(
[0] => stdclass object(
[title] => John
[id] =>55
[class] => six)
[1] => stdclass object(
[title] => Doe
[id] =>550
[class] => six)
[2] => stdclass object(
[title] => Jean
[id] =>9
[class] => one)
[3] => stdclass object(
[title] => AI
[id] =>90
[class] => one)
)
)
[1]=>stdclass object(
[_id] => MongoDB\BSON\ObjectId Object (
[oid] => 5f
)
[title] => sunny
[roll.n] => 50
[detail] => Array(
[0] => stdclass object (
[title] => lilly
[id] =>551
[class] => six)
[1] => stdclass object(
[title] => Doel
[id] =>550
[class] => six)
[2] => stdclass object(
[title] => rehaman
[id] =>9
[class] => one
)
)
)
扬帆大鱼