tags:

views:

37

answers:

1

I have a script that i wrote, but it prints the first part of the array twice.

The output that i get is the following:

2009_06_09_02_07_57_Phase2_04.jpg 2009_06_09_02_07_33_Phase2_03.jpg 2009_06_09_02_07_57_Phase2_04.jpg

The code is below:

   $currentPath = $path.'images/galleries/phase2/folder1/';

   $dirNew = opendir($currentPath);

          while ($file = readdir($dirNew)) {
              if($file != "." && $file != ".." && $file != "Thumbs.db" && $file != "index.html" && $file != "index.php") { 
       $dirArray[] = $file;

       $indexCount = count($dirArray);

       sort($dirArray);
       for($i=0; $i < $indexCount; $i++) {
        print $dirArray[$i].'<br />';

      /*echo '<br /><a href="'.$currentPath.$dirArray[$i].'" title="image 1" class="thickbox" rel="phase 2">
<img src="'.$currentPath.$dirArray[$i].'" width="75" height="75" border="0"></a><br /><br />
Click image <br />for slideshow';*/

       }

     }
          }
          closedir($dirNew);


  }

Any pointers in the right direction will be welcome.

Thanks in Advance

+1  A: 
$indexCount = count($dirArray);

sort($dirArray);
for($i=0; $i < $indexCount; $i++) {
       print $dirArray[$i].'<br />';

Move it after the while {}

valya
Right, to elaborate you're printing your array through each iteration of the while loop. If you had more than 3 items the problem would compound. Build your array first and then sort and output it outside of the loop.
Rob