Home > php教程 > php手册 > php数组索引的Key加引号和不加引号的区别

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

WBOY
Release: 2016-06-06 20:19:20
Original
1564 people have browsed it

这篇文章主要介绍了php数组索引的Key加引号和不加引号的区别,加引号和不加引号是有严重的区别的,需要的朋友可以参考下

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

复制代码 代码如下:


define('WEBHOST','blog');

$wso = array();

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

$wso['WEBHOST'] = 'www.jb51.net';

echo $wso[WEBHOST];  //output


果然,输出的竟然是,而不是。现在知道索引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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template