数组结构:
array (
'payee_id' => 2381,
'items' =>
array (
300 =>
array (
'item_id' => 300,
' price' => 50,
),
372 =>
array (
'item_id' => 372,
'price' => 90,
),
),
)
我正在尝试动态获取item_id
和price
。
代码
foreach($data as $key => $value) {
Log::debug($value[300]['price']);
}
使用上面的代码,我可以获取密钥300
price
,但是我也需要获取密钥372
。
答案 0 :(得分:1)
使用foreach()
<?php
foreach($data as $key => $value) { // if `$data` equal to $data['items'] as you mentioned in your question `Log::debug($value[300]['price']);`
foreach ($value as $finalValue) { // loop for inner array
echo $finalValue['price']."<br/>"; // print price in new line
}
}
?>