PHP function, a little help
<p>I need a function which searches a dir for UP TO 5 files (only MAX 5 files in the dir). The files have the same names almost, an ID nr ending with <code>'_1'</code> for <code>file</code> 1, <code>'_2'</code> for <code>file 2</code> etc. It simply ends with a underscore, and then the file-nr. Example:</p>

<pre><code>   filename = id.'_1.jpg'; // File 1.
</code></pre>

<p>Here is the tricky part, read carefully: Now I need to search this dir and if there is (for example) <code>a file1, and file3, BUT NO file2, then rename file3 to file2.</code></p>

<p>In other words, I need to find 'gaps' between the names and rename all files so they come in order, without 'gaps'.</p>

<p>So another example, if dir contains 3 files ending with <code>'_1.jpg' and '_3.jpg' and '_4.jpg'</code> I want it to rename the files so that they are <code>'_1.jpg' and '_2.jpg' and '_3.jpg'</code>, they come in order...</p>

<p>As I said there is max 5 files in this folder.</p>

<p>Please help me out... I am not that good in writing functions in PHP... 
Thanks</p>

<p>PS: If I'm not clear, let me know and I will put in some more examples...</p>
