I'm having some trouble understanding arrays... I've borrowed and rewritten scripting that gets the contents of a folder, sorts by file date, then prints out the contents.
I'm having trouble pulling certain information out, like only a certain number of files, and not the entire array.
I don't think I understand how my array is working... I grasp the keys/values but can't quite apply it to this code...
What I'd like to do is only print say the first 5 entries...
Here is the link to the page:
http://www.jasonthomasfrance.com/testscript/
And here is the coding I'm working with:
Code: Select all
<?php
echo "This script gets all image files, sorts by date, and prints them out. Next I'm working out how to display X number per page and traverse the pages...<br><br> \n";
$dir='thumbs';
if ($handle = opendir($dir))
{
$lasttime=0;
$images=array();
while (false !== ($file = readdir($handle)))
{
if(is_file($file))$images[$file]=filemtime($file);
}
}
arsort($images,SORT_NUMERIC);
reset($images);
while(list($filenames,$v)=each($images))
echo "<a href=\"$filenames\"><img src=\"$dir/$filenames\" alt=\"$filenames\" border=\"0\"></a> \n";
$result = count ($images);
echo "<br><br>File count: $result <br>";
reset($images);
for ($n = 0; $n < count($images); $n++) {
$Line = each ($images);
print ("$Line[0], ");
}
?>