2014-01-23 144 views
0

我有一個多維數組,如下所示,我只想獲得底部[image_meta]數組中的[caption]的值。多維數組foreach

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]; 
} 
+0

'var_dump($ x);'每當你不知道變量是什麼時,使用'var_dump' – zerkms

回答

1

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

0

你並不需要一個循環得到一個值。你可以這樣做:

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