我试图从另一个数组中的数组中获取值。我在这里看到了很多关于此的答案,但我无法做到这一点。我有一个像这样的数组:
Array
(
[0] => Array
(
[listingid] => 1234
[availability] => Array
(
[0] => Array
(
[von] => 2015-11-07
[bis] => 2016-03-19
)
[1] => Array
(
[von] => 2016-03-19
[bis] => 2016-03-28
)
[2] => Array
(
[von] => 2016-03-28
[bis] => 2016-07-30
)
)
)
[1] => Array
(
[listingid] => 5678
[availability] => Array
(
[0] => Array
(
[von] => 2015-11-07
[bis] => 2016-03-19
)
[1] => Array
(
[von] => 2016-03-19
[bis] => 2016-03-28
)
[2] => Array
(
[von] => 2016-03-28
[bis] => 2016-07-30
)
)
)
)
我这样做是为了获得价值:
foreach($first as $key => $value){
echo "Value: " . $value[$key]['availability']['von'] . "<br>";
}
通常应该根据我看到的答案工作,但它给了我空值。
我也试过这个:
foreach($first as $key => $value){
$listid = $value['listingid'];
echo $listid;
}
这给了我listingid的值。我怎样才能获得von和bis的值?
有什么建议吗?
答案 0 :(得分:1)
您只需要运行嵌套循环。
foreach($first as $value){
echo "Listing ID:".$value['listingid'];
echo "<br/>";
foreach($value['availability'] as $availability) {
echo "Value: " . $availability['von'] . "<br>";
}
}