assigning variables from $key and $value for all objects in the array
<p>I have a function that I need to pass 4 distinct variables to, and these variables values come from an array:</p>

<pre><code>$pagesArray = array(
                   'pre-file1.html' =&gt; 'blahblah1',
                   'post-file1.html' =&gt; 'blahblah2'
                    );

$file1 = 'blahblah1';

$file2 = 'blahblah2';

$file1Name = 'pre-file1.html';

$file2Name = 'post-file1.html';
</code></pre>

<p>How do I assign in a <code>foreach</code> loop when I'm calling the function in the loop too?</p>

<p>I've tried this</p>

<pre><code>foreach ($pagesArray as $fileName =&gt; $url)
{
    $file1 = file($url);
    $file2 = file($url);
    $file1Name = $key;
    $file2Name = $key;


    compareFiles($file1, $file2, $file1Name, $file2Name);

}
</code></pre>

<p>But that doesn't work because it's calling the function in the loop and will only loop over after it's called every time.</p>

<p>NB: the above is only an example, there will be more objects in that array than the two currently shown.</p>
