慕仰0522570
$arr = [
[
"attr_id": "11",
"attr_price": "29.8",
"attr_value": "蓝色",
"goods_attr_id": "31",
"goods_id": "10"
],
[
"attr_id": "8",
"attr_price": "29.8",
"attr_value": "60CM",
"goods_attr_id": "29",
"goods_id": "10"
],
[
"attr_id": "8",
"attr_price": "29.8",
"attr_value": "70CM",
"goods_attr_id": "30",
"goods_id": "10"
],
[
"attr_id": "11",
"attr_price": "29.8",
"attr_value": "黑色",
"goods_attr_id": "28",
"goods_id": "10"
]
]
$arr1 = [];
foreach ($arr as $k => $v) {
$arr1[$v[attr_id]][] = $v;
}
// 输出
$arr1 = [
'8' => [
[
"attr_id": "8",
"attr_price": "29.8",
"attr_value": "70CM",
"goods_attr_id": "30",
"goods_id": "10"
],
[
"attr_id": "8",
"attr_price": "29.8",
"attr_value": "60CM",
"goods_attr_id": "30",
"goods_id": "10"
],
],
'11' => [
[
"attr_id": "11",
"attr_price": "29.8",
"attr_value": "蓝色",
"goods_attr_id": "31",
"goods_id": "10"
],
[
"attr_id": "11",
"attr_price": "29.8",
"attr_value": "黑色",
"goods_attr_id": "28",
"goods_id": "10"
],
],
]