我在这里唯一关心的是尺寸。我需要闯入一个新级别的数组并将其添加进去,将它们分组在一起。我基本上需要将它们全部分组在自己的数组中,这样我就可以循环它们并执行其他操作。当前数组:[0] => Array ( [name] => random name 2 [sizes] => ["XS","S","M","L","XL","XXL"] )[1] => Array ( [name] => random name 1 [sizes] => One Size )[2] => Array ( [name] => random name 3 [sizes] => ["XS","S","M","L","XL","XXL"] )通缉:[0] => Array ( [0] => Array ( [name] => random name 1 [sizes] => One Size ) )[1] => Array ( [0] => Array ( [name] => random name 2 [sizes] => ["XS","S","M","L","XL","XXL"] ) [1] => Array ( [name] => random name 3 [sizes] => ["XS","S","M","L","XL","XXL"] ) )
1 回答
ITMISS
TA贡献1871条经验 获得超8个赞
循环数组并创建一个新数组,暂时将大小作为键。
稍后,我们使用 array_values 删除关联键。
foreach($arr as $item){
$new[$item['sizes']][] = $item;
}
$new = array_values($new); // remove associative
- 1 回答
- 0 关注
- 100 浏览
添加回答
举报
0/150
提交
取消