我正在使用关联数组来构建专辑列表以及这些专辑中的图像。该数组是使用以下代码构建的(为清楚起见,省略了一些代码 - 只是加载的东西$title
,$desc
等):
<?php
$directory = 'gallery/*';
$subfolders = glob($directory);
foreach($subfolders as $subfolder) {
$photos = glob($subfolder.'/*.[Jj][Pp][Gg]');
$album = explode('_', $subfolder);
$albumname = str_replace(' ','%20',$album[1]);
foreach($photos as $photo){
$photolist[$albumname] .= '<span data-title="'.$title.'" data-desc="'.$desc.'" data-camera="'.$camera.'" data-lens="'.$lens.'" data-length="'.$length.'" data-shutter="'.$shutter.'" data-aperture="'.$aperture.'" data-iso="'.$iso.'" style="background-image:url('.$photo.'); background-size:contain;" class="slide"></span>';
}
}
?>
我正在尝试implode()
根据(从cookie中读取)来吐出相关元素$currentalbum
,如下所示:
<?php
if(isset($_COOKIE["currentalbum"])) {
$currentalbum = $_COOKIE["currentalbum"];
} else {
$currentalbum = "New";
}
$currentphotolist = implode("",$photolist[$currentalbum]);
echo $currentphotolist;
?>
这是返回错误:
警告:implode() [function.implode]:第 97 行的 index.php 中传递的参数无效
我认为数组有问题,但是当我print_r()
这样做时,我得到以下内容,看起来不错:
Array
(
[New] => <span data-title="Train" data-desc="This is a picture of a train. Look at it go!" data-camera="Nikon D300" data-lens="Tamron 17-50mm f/2.8 VC" data-length="17mm" data-shutter="1/250s" data-aperture="f/6.3" data-iso="200" style="background-image:url(gallery/01_New/Train.jpg); background-size:contain;" class="slide"></span><span data-title="Billow" data-desc="" data-camera="Nikon D300" data-lens="Nikkor 50mm f/1.8D" data-length="50mm" data-shutter="1/250s" data-aperture="f/8" data-iso="200" style="background-image:url(gallery/01_New/Billow.jpg); background-size:contain;" class="slide"></span><span data-title="3059" data-desc="" data-camera="Nikon D300" data-lens="Micro-Nikkor 105mm f/2.8 VR" data-length="105mm" data-shutter="1/30s" data-aperture="f/22" data-iso="200" style="background-image:url(gallery/01_New/3059.jpg); background-size:contain;" class="slide"></span>
[Landscapes] => <span data-title="Influx" data-desc="" data-camera="Nikon D300" data-lens="Nikkor 70-300mm f/4.5-5.6 VR" data-length="70mm" data-shutter="30s" data-aperture="f/8" data-iso="200" style="background-image:url(gallery/02_Landscapes/Influx.jpg); background-size:contain;" class="slide"></span>
[Constructs] => <span data-title="Fervor" data-desc="I took this while wandering around in SEA-TAC airport waiting for a flight home. It\'s a lantern, hanging with some others in a shop. It caught my eye from across the terminal, but the shop was pretty small and I\'m always a little worried about knocking stuff with my camera bag, so I shot it through the window. I think it turned out pretty well regardless." data-camera="Nikon D7000" data-lens="Tamron 17-50mm f/2.8 VC" data-length="50mm" data-shutter="1/60s" data-aperture="f/2.8" data-iso="180" style="background-image:url(gallery/03_Constructs/Fervor.jpg); background-size:contain;" class="slide"></span>
)
知道为什么我会收到错误吗?