多维数组不能



我有这个数组:

array:2 [▼
0 => array:6 [▼
"id" => 1
"name" => "Longline T-Shirt In Fake Linen With All Over Floral Print"
"price" => 18.11
"quantity" => 1
"attributes" => []
"conditions" => []
]
1 => array:6 [▼
"id" => 3
"name" => "Longline T-Shirt With All Over Aztec Print"
"price" => 16.99
"quantity" => 1
"attributes" => []
"conditions" => []
]
]

(来自拉拉维尔的DD(

但是当我在数组 ($all_order( 上运行 foreach 时,它只返回我的第一个细节。

尝试使用:

$result = [];
array_walk_recursive($all_order, function($v) use (&$result) {
$result[] = $v;
});
dd( $result);

结果:

0 => 1
1 => "Longline T-Shirt In Fake Linen With All Over Floral Print"
2 => 18.11
3 => 1
4 => 3
5 => "Longline T-Shirt With All Over Aztec Print"
6 => 16.99
7 => 1

问题是,我只需要id +数量就可以降低产品表中的库存价值。我堆了大约 4 个小时-_-">

我猜你的原始 foreach 代码有错误。这是您通常的做法:

foreach ($all_order as $value) {
$id = $value['id'];
$quantity = $value['quantity'];
// then do something with your values...
}

相关内容

最新更新