有没有更好的方法来做这样的事情?这很好,但我认为可能有一条捷径可以得到相同的结果。我想很容易添加更多的数组,我可以把它变成一个函数,然后在它外面有 for 循环,但仍然如此。
就是想。
<?
$array1 = array("test1","test2","test3","test4");
$array2 = array("dest1","test2","dest3","dest4");
for ($i=0; $i<count($array1); $i++) { //FOR STATEMENT TO GET MULTIPLE ARRAYS REGISTERED AS A FOREACH-STYLE
$val1 = $array1[$i]; //VALUES GET
$val2 = $array2[$i];
$array1 = array_flip($array1); //ARRAY IS FLIPPED FROM KEY => VALUE TO VALUE => KEY SO THAT THE KEYS CAN BE GET. REMEMBER TO SWITCH IT BACK.
$array2 = array_flip($array2);
$key1 = $array1[$val1]; //NOW MUST ITERATE THROUGH USING VALUES ABOVE BECAUSE THE KEYS ARE NO LONGER NUMBERS.
$key2 = $array2[$val2];
$array1 = array_flip($array1); //SWITCHING IT BACK.
$array2 = array_flip($array2);
echo $key1 . "=>" . $val1 . "<br />";
echo $key2 . "=>" . $val2 . "<br />";
}
var_dump($array1);
?>