Reusing the same function and efficiency in php
<p>I have a function that creates an gathers files from a directory and puts them into an array.</p>

<pre><code>function getFiles($folder){
    $ignore = array("index.php",".","..","favicon.gif","favicon.ico",".DS_Store");
    $gottenFiles = array();
        if ($handle = opendir($folder)) {       
            while (false !== ($file = readdir($handle))) {
                if (in_array($file, $ignore)){
                    //do nothing
                }else{
                    array_push($gottenFiles, $file);
                }
            }
        closedir($handle);
        }
    return $gottenFiles;
}
</code></pre>

<p>The problem I am trying to wrap my head around is that of efficiency. <strong>Everytime I run</strong> <code>getFiles("folder");</code> <strong>it runs through the whole process of reassembling the array.</strong> I dabbled a bit into static variables and isset conditionals with no progress. Would it be better to call the function inside a variable like this <code>$filesArray = getFiles("folder");</code> and reuse <code>$filesArray</code>. </p>

<p>Is their a way to set the array once and not continue with opendir?</p>

<p>Are their any modifications I can do to the function above? (the //do nothing conditional?)</p>

<p>Thanks in advance!</p>
