PHP array index key plus quotes and no quotes _php tips

Source: Internet
Author: User
Tags constant webhost

Look at a PHP blog today and note that: "The index key value in PHP, if not enclosed in quotes, interprets the index key value as a constant, which is interpreted as a string when no definition of the constant is found." I'm a little bit convinced because I always enclose the index key in quotes, so this doesn't happen. Take the time to write a line of code to test it:

Copy Code code as follows:

Define (' webhost ', ' blog ');

$WSO = Array ();

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

$WSO [' webhost '] = ' www.jb51.net ';

echo $wso [webhost]; Output www.weixiaodeyu.com


Sure enough, the output turned out to be www.weixiaodeyu.com, not www.jb51.net. Now you know the importance of index key values plus quotes. If there is an unexpected mistake, check it. In fact, the strict implementation of the language specification will not appear this difficult to debug errors.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.