php数组取相同的元素个数组,求教PHP中多维数组中相同的值提取归类

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-1 18:31   11   0

例 PHP中有这么一个多维数组

Array[4][

{

"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"

}

]

求教要怎么想相同的 “attr_id” 提取到一个新的数组中 如:

$arr = new arrry();

$arr["a"] = [

{

"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": "70CM",

"goods_attr_id": "30",

"goods_id": "10"

},

]

$arr["b"] = [

{

"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"

}

]

数组长度不确定、attr_id值、数量不确定,就是要判断将数组中的attr_id相同的归类放入新的数组中.

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP