我正在使用数组,而我正在做一些与数组略有关系的事情,但我没有改变它,但它正在改变。这是代码:
echo "\n\r\n\rLine563: "; print_r($array); echo "\n\r";
// Check for empty fields, stop processing, and save to empty lines file
$isEmpty = false;
$temp_array = $array;
foreach($temp_array as $i){
if(preg_match("/^\s*$/", $i)){
$isEmpty = true;
}
}
echo "\n\r\n\rLine572: "; print_r($array); echo "\n\r";
这就是我得到的:
Line563: Array
(
[type] => Science
[type2] => 1
[text] => When was the first lunar landing?
[WRONG answer1] => 1947
[WRONG answer2] => 1968
[WRONG answer3] => 1970
[CORRECT] => 1959
)
Line572: Array
(
[type] => Science
[type2] => 1
[text] => When was the first lunar landing?
[WRONG answer1] => 1947
[WRONG answer2] => 1968
[WRONG answer3] => 1970
[CORRECT] => 1970
)
如果我注释掉该代码,它就可以正常工作(因为我只需要打印数组两次,并在其间插入注释)。
另外,作为一个注释,我意识到像这样的foreach循环是低效的(人们应该知道的事情)。
所以,这里有一些有趣的东西,它被改变了:
$isEmpty = false;
当我评论该行时,它工作正常。我不知道为什么。这是第一次在脚本中声明此变量。