【发布时间】:2014-11-28 02:31:39
【问题描述】:
为什么不取消设置从我回显的结果中删除 index.php?
$files = array(
'0' => 'bob.php',
'1' => 'index.php',
'2' => 'fred.php'
);
foreach ($files as $key => &$file) {
if(in_array($file, array('index.php'))) {
echo 'test condition<br />'; // Yes, this condition is met
unset($files[$key]);
}
echo '<a href="'.$file.'">'.$file.'</a><br />'."\n";
}
为了做到这一点,我实际上遵循了this stackoverflow question 的答案。
【问题讨论】:
-
您只是从
$files数组中删除一个条目。这不会取消设置本地$file字符串也不会跳过后续的echo。 -
显然取消设置数组索引不会影响引用变量。您必须为数组索引分配一些东西才能更改引用。
-
删除元素后你希望它回显什么?