多维数组foreach

时间:2014-01-23 23:44:32

标签: php arrays multidimensional-array

我有一个多维数组,如下所示,我想简单地得到[caption]的值,它位于底部的[image_meta]数组中。

Array
(
[file] => 2014/01/dreamstimecomp_5449062.jpg
[sizes] => Array
    (
        [thumbnail] => Array
            (
                [file] => dreamstimecomp_5449062-150x150.jpg
            )

        [medium] => Array
            (
                [file] => dreamstimecomp_5449062-300x224.jpg
            )

    )

[image_meta] => Array
    (
        [aperture] => 0
        [credit] => 
        [camera] => 
        [caption] => 
        [created_timestamp] => 0
        [copyright] => 
        [focal_length] => 0
        [iso] => 0
        [shutter_speed] => 0
        [title] => 
    )

我已经为下面的每个循环尝试了这个但是没有工作

echo '<pre>';
print_r($caption_data); 
echo '</pre>';
foreach ($caption_data as $x=>$x_value){
    echo $x[0][3];
}

2 个答案:

答案 0 :(得分:1)

echo $caption_data['image_meta']['caption']

答案 1 :(得分:0)

您不需要循环来获取单个值。你可以这样做:

$value = $array_containing_datastructure['image_meta']['caption'];