如何处理数组中的数组?
像这样:
Array
(
[page] => 1
[pages] => 391
[perpage] => 3
[total] => 1171
[photo] => Array
(
[0] => Array
(
[id] => 4539740346
[owner] => 21229296@N03
[secret] => 3b10921450
[server] => 4040
[farm] => 5
[title] => ~ Berry One ~
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
)
编辑: 如何回显所有内容? 数组如下所示: http://www.qeeker.com/flickr
您可以像这样从数组中获取值:
echo $a['photo'][0]['ispublic']; //1
更新:
在评论中您表示您想要显示照片内容。在 PHP 中,
foreach
可用于迭代数组:
foreach ($a['photo'] as $photo) {
//$photo refers to the current photo on every iteration
echo $photo['ispublic'];
}
此片段将呼应数组中每张照片的
ispublic
属性。如果您想回显所有照片的所有属性,您可以使用嵌套的 foreach
(一个在另一个里面)。
$var = array('page' => 1,
'pages' => 391,
'perpage' => 3,
'total' => 1171,
'photo' => array(array('id' => 4539740346,
'owner' => '21229296@N03'
'secret' => '3b10921450'
'server' => 4040
'farm' => 5
'title' => '~ Berry One ~'
'ispublic' => 1
'isfriend' => 0
'isfamily' => 0
)
)
);
var_dump($var);