I have a function that I need to pass 4 distinct variables to, and these variables values come from an array:
$pagesArray = array(
'pre-file1.html' => 'blahblah1',
'post-file1.html' => 'blahblah2'
);
$file1 = 'blahblah1';
$file2 = 'blahblah2';
$file1Name = 'pre-file1.html';
$file2Name = 'post-file1.html';
How do I assign in a foreach loop when I’m calling the function in the loop too?
I’ve tried this
foreach ($pagesArray as $fileName => $url)
{
$file1 = file($url);
$file2 = file($url);
$file1Name = $key;
$file2Name = $key;
compareFiles($file1, $file2, $file1Name, $file2Name);
}
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.
NB: the above is only an example, there will be more objects in that array than the two currently shown.
1 Answer