php数组索引的Key加引号和不加引号的区别_PHP

WBOY
Release: 2016-05-31 19:30:31
Original
826 people have browsed it

今天在看一个PHP博客时留意了这么一句话:“PHP中的索引KEY值如果不用引号括起来的话,会将索引KEY值解释为一个常量,当找不到该常量的定义时,才将其解释为一个字符串”。我有点不太相信,因为我一直都会将索引KEY用引号括起来,从而没有出现这种情况。趁现在有时间正好写行代码测试一下:

代码如下:


define('WEBHOST','blog');

$wso = array();

$wso['blog'] = 'www.weixiaodeyu.com';

$wso['WEBHOST'] = 'www.bitsCN.com';

echo $wso[WEBHOST];  //output www.weixiaodeyu.com


果然,输出的竟然是www.weixiaodeyu.com,而不是www.bitsCN.com。现在知道索引KEY值加上引号的重要性了吧。如果出现了意想不到的错误可要检查一下了。其实严格执行语言规范就不会出现这种难以调试的错误。
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!