Array splice and unset
Posted: Tue Jan 26, 2010 3:26 pm
Hi,
I have created this code to scan a directory and create a Light box gallery for each of them but for some reason when I run it i am getting 3 of the first file (the one that name should be) in each gallery and can't work out why?
Here is my code:
Thanks for any help
Please ask if you want anymore info.
Tsail
I have created this code to scan a directory and create a Light box gallery for each of them but for some reason when I run it i am getting 3 of the first file (the one that name should be) in each gallery and can't work out why?
Here is my code:
Code: Select all
<?php
$dir = '../../Gallery/2009/';
$files1 = scandir($dir);
unset($files1[0], $files1[1]);
foreach ($files1 as $value) {
$sub = scandir($dir . $value) ;
unset($sub[0], $sub[1], $sub[2]);
$name = scandir($dir . $value) ;
unset($name[0], $name[1]);
array_splice($name, 1);
$first = implode($name);
echo "<p> <a href=\"$dir$value/$first\" rel=\"lightbox[$value]\" title=\"$first\"><img src=\"$dir$value/$first\" Height=25% width=25%</a></p> <p>$value</p>" ;
foreach($sub as $value2)
$result = count($sub);
if ($result > 0)
foreach ($sub as $value2) {
echo "<a href=\"$dir$value/$value2\" rel=\"lightbox[$value]\" title=\"$value2\"></a>";
}
}
?>Please ask if you want anymore info.
Tsail