我环顾四周但是我不确定我能找到具体的答案,所以如果我错过了合适的帖子我会道歉,请将我链接到它:)
我正在创建一个脚本来搜索文件夹以查找更多文件夹,并将每个文件夹中所有文件的列表编译成一个多数组。文件夹名称将是随机的,所以我对如何使用foreach循环提取它们感到有点迷失。
我也对“ [0] =>数组”中的第二个数组感到困惑。我脚本中的输出数据目前如下所示:
Array
(
[0] => Array
(
[folders] => Array
(
[album 1] => Array
(
[0] => wallpaper-1089283.jpg
[1] => wallpaper-2549931.png
[2] => wallpaper-379108.jpg
[3] => wallpaper-38130.jpg
)
[album 2] => Array
(
[0] => ns75FqFLk1v6jEmecgu25IOk8yB.jpg
[1] => wallpaper-1627330.jpg
[2] => wallpaper-1629402.jpg
)
[album 3] => Array
(
[0] => wallpaper-1042083.jpg
[1] => wallpaper-176023.jpg
[2] => wallpaper-2624435.jpg
)
)
)
)
所以我真的希望将这些数据输出到某些html,如下所示。我并没有真正完成多阵列的工作,我希望我能学到:)
<div>
<img src="image.jpg"/>
<img src="image.jpg"/>
<img src="image.jpg"/>
</div>
<div>
<img src="image.jpg"/>
<img src="image.jpg"/>
<img src="image.jpg"/>
</div>
<div>
<img src="image.jpg"/>
<img src="image.jpg"/>
<img src="image.jpg"/>
</div>
答案 0 :(得分:2)
foreach ($array[0]['folders'] as $albumID => $images) {
... <div> ...
foreach($images as $img) {
.... <img> here ...
}
.... </div>
}
答案 1 :(得分:0)
foreach($array[0]['folders'] as $albumarray)
{
echo "<div>";
foreach(albumarray as $img)
{
echo '<img src="'.$img.'"/>'
}
echo "</div>";
}
答案 2 :(得分:0)
试试这个:
foreach($data as $singleFolder) {
echo '<div>';
foreach($singleFolder as $img){
echo "<img src='$img' />";
}
echo '</div>'
}
答案 3 :(得分:0)
$array = array(
0 => array(
'folders' => array(
'album 1' => array(
0 => 'wallpaper1.jpg',
2 => 'wallpaper1.jpg',
3 => 'wallpaper1.jpg',
),
'album 2' => array(
0 => 'wallpaper1.jpg',
2 => 'wallpaper1.jpg',
3 => 'wallpaper1.jpg',
),
'album 3' => array(
0 => 'wallpaper1.jpg',
2 => 'wallpaper1.jpg',
3 => 'wallpaper1.jpg',
)
)
)
);
$output = '';
foreach ($array[0]['folders'] as $key => $value) {
$output .= '<div>\n';
foreach ($value as $file) {
$output .= '\t<img src="'.$file.'" />\n';
}
$output .= '</div>\n';
}
echo $output;
答案 4 :(得分:0)
尝试这样的事情。
$albums = $array[0]['folders'];
foreach ($album as $img_array)
{
echo "<div>";
foreach ($img_array as $img)
{
echo "<img src='".$img."'/>";
}
echo "</div>";
}