从$key和$value中为数组中的所有对象分配变量


assigning variables from $key and $value for all objects in the array

我有一个函数,我需要传递4个不同的变量,这些变量的值来自一个数组:

$pagesArray = array(
                   'pre-file1.html' => 'blahblah1',
                   'post-file1.html' => 'blahblah2'
                    );
$file1 = 'blahblah1';
$file2 = 'blahblah2';
$file1Name = 'pre-file1.html';
$file2Name = 'post-file1.html';

当我在循环中调用函数时,我如何在foreach循环中分配?

我试过了

foreach ($pagesArray as $fileName => $url)
{
    $file1 = file($url);
    $file2 = file($url);
    $file1Name = $key;
    $file2Name = $key;

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

但是这不起作用,因为它在循环中调用函数,并且只会在每次调用后循环。

注意:上面只是一个例子,在这个数组中会有比现在显示的两个对象更多的对象

list($file1, $file2)         = array_values($pagesArray);
list($file1Name, $file2Name) = array_keys($pagesArray);
compareFiles($file1, $file2, $file1Name, $file2Name);