是否有任何工具可以运行PHP代码,如果我键入这样的东西就可以运行?
$myarray = array(
'foo' => 'hello',
'bar' => 'goodbye',
'foo' => 'hello again' // <= need to pick up the duplicate key on this line
);
编辑:我想要this之类的东西,但不是专有的。
答案 0 :(得分:0)
您正在覆盖您的数组键,因此PHP只会在键'foo'的最后一个条目上拾取
$arr = array(
'foo' => 'hello',
'bar' => 'goodbye',
'foo' => 'hello again' // <= need to pick up the duplicate key on this line
);
print_r($arr);
返回:
数组([foo] =&gt;再次问好[bar] =&gt;再见)
BUT:
$arr = array(
'foo' => 'hello',
'bar' => 'goodbye',
'foo3' => 'hello again' // <= need to pick up the duplicate key on this line
);
print_r($arr);
返回:
数组([foo] =&gt; hello [bar] =&gt;再见[foo3] =&gt;再次问好)
甚至在foreach循环中(踩过你的数组)
$arr = array(
'foo' => 'hello',
'bar' => 'goodbye',
'foo' => 'hello again' // <= need to pick up the duplicate key on this line
);
foreach ($arr AS $Keys => $Value)
{
echo $Keys;
echo "<br>";
}
返回:
bar
foo
整体道德:
您的数组键被覆盖,因此PHP无法识别重复键。