array:2 [▼
"aa" => array:6 [▼
"comboNameId" => 1
"sku" => "aa"
"lineItem" => "x"
"qty" => 1
"lineItem1" => "y"
"qty1" => 2
]
"bb" => array:8 [▼
"comboNameId" => 1
"sku" => "bb"
"lineItem" => "111"
"qty" => 111
"lineItem1" => "222"
"qty1" => 2
"lineItem2" => "333"
"qty2" => 3
]
]这个是我循环得到的一个数组,现在我需要找到这个二维数组最多个数的那一个放到数组最上面去就好,不需要将数组进行排序。请问如何实现呀?
1 回答
繁星淼淼
TA贡献1775条经验 获得超11个赞
`
//$arr是原数组,temp是临时保存数组
foreach ($arr as $k => $v) {
$temp[$k] = count($v);
}
//对数组的个数排序,多个排前面
arsort($temp);
//重新组合组合$res,就是目标结果
foreach ($temp as $k => $v) {
$res[$k] = $arr[$k];
}
`
- 1 回答
- 0 关注
- 152 浏览
添加回答
举报
0/150
提交
取消