Home  >  Article  >  Backend Development  >  php数组的简单有关问题

php数组的简单有关问题

WBOY
WBOYOriginal
2016-06-13 12:59:58988browse

php数组的简单问题

$arr=array(“foo” => “bar”, 12=> true);
echo $arr[“foo”];//输出bar
echo $arr[12];//输出1
?>
 谁能帮我解释一下这个数组问题,这个true为什么改成false就报错
------解决方案--------------------
报什么错?
应该不会啊,只是没有输出而已
------解决方案--------------------
$arr=array('foo' => 'bar', 12=> false);
echo $arr['foo'];//输出bar
echo $arr[12];//报错?

怎么可能?
------解决方案--------------------
加引号就可以了!
------解决方案--------------------
本地测试
程序无错误。。
------解决方案--------------------
试了一下,没错啊~ 楼主,求你的源代码~ 怎么错的。。~
------解决方案--------------------
改成false是不会报错的,但是不会输出。因为php里面false就是空。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn