Add more then 1 item to a PHP array and iterate it
<p>Below is a file iterarot unction I have working on that iterates over folders and gathers all images, it saves each image's file path to a <code>$files array</code> and then later on the code has to iterate over that <code>$files array</code></p>

<p>Right now the code I am working on actually sens a file through imagemagick 3 times ( I didn't write the original code) so I am trying to improve the whole code, So far I have cut that down to 2 times and when this is finished it will be only 1 time for each image.</p>

<p>Basically the current code runs an image through imagemagick to see it it is an image or not, later on it does it again but this time to get the image extension, and then the 3rd time was to make sure it was an image again (I know pretty crazy that people write code that bad)</p>

<p>So to reduce it to 1 time, when the <code>$files array</code> runs an image file through imagemagick the first time to make sure it is an image, I now have that function returning the file extension instead of a simple true/false.  So when the filepath is saved to the array I would like to save the returned file extension to the array with that particular file path so that I can access it later without running imagemagick again.</p>

<p>So here is the function that cycle thorough folders grabbing all image files and then sends them to imagemagick.  It then saves the filepath to the array, can someone show me how to save the file extension to this array and then how to access it in the code below the function</p>

<pre><code>function find_recursive_images($path)
{
    $directory = new RecursiveDirectoryIterator($path,RecursiveDirectoryIterator::SKIP_DOTS);
    $iterator = new RecursiveIteratorIterator($directory,RecursiveIteratorIterator::LEAVES_ONLY);
    $exntensions = array("png", "jpg", "jpeg", "gif", "bmp");

    foreach ($iterator as $fileinfo) {
        if (in_array($fileinfo-&gt;getExtension(), $exntensions)) {
            //This gets the filetype of the image from ImageMagick
            $img = self::get_type($fileinfo-&gt;getPathname());
            if ($img) {
                //This sets the full file path to the $files array
                $files[] = $fileinfo-&gt;getPathname();

                // I tried something like this but not correct
                $files[][] = $img;
            }
        }
    }
    return $files;
}
</code></pre>

<p>I then access the array like this right now...</p>

<pre><code>foreach ($files as $file)
{    
     // ie E:\Server\_ImageOptimize\img\testfiles\css3-please.png
     $source_file = $file;  

    // $file also needs to return a filetype that is got when it ran thorugh imagemagick

}
</code></pre>
