谁能解释一下为什么这段代码:
<pre>
<?php
$a = array('page', 'email', 'comment');
$b = array('page' => 'realpage', 'email' => 'reaLmail', 'comment' => 'c');
$c = array();
foreach ($a as &$item) {
if (isset($b[$item])) {
$item = $b[$item];
}
}
foreach ($a as $item) {
$c[] = $item;
}
print_r($c);
输出
Array
(
[0] => realpage
[1] => reaLmail
[2] => reaLmail
)
???为什么在第二个循环 a 之前是(通过 var_dump)
array(3) {
[0]=>
string(8) "realpage"
[1]=>
string(8) "reaLmail"
[2]=>
&string(1) "c"
}
但在第一次迭代中,a 是
array(3) {
[0]=>
string(8) "realpage"
[1]=>
string(8) "reaLmail"
[2]=>
&string(8) "realpage"
}
并且在第二个和第三个 [1] 和 [2] 索引上是相同的“realmail”,而 [2] 是指针?谢谢!