how do i modify the way in wich readdir() lists files
<p>I have a script that creates a <code>zip</code> package daily in a directory. After this is done another script deletes the 'last' file in the directory so I always have just the latest x days.</p>

<pre><code>while (false !== ($file = readdir($handle))) 
    {
            if ($file != "." &amp;&amp; $file != "..")
            {
                echo "$file";
                echo '&lt;br&gt;';

                //count files
                $file_count = $file_count + 1;
            }
        }
</code></pre>

<p>However suddenly <code>readdir()</code> is returning the list of files like this:</p>

<pre><code>March_16_2011.zip

March_12_2011.zip

March_13_2011.zip

March_14_2011.zip

March_15_2011.zip
</code></pre>

<p>So of course rather than the oldest file being removed the newest one is.</p>

<p>When I look at the files in FTP they are all dated correctly.</p>

<p>Why is <code>readdir()</code> returning them out of order in this case? How do I force it to order them in a way I want? (By date)</p>
