Difference between keys of php array indexes enclosed by quotation marks and without quotation marks

Source: Internet
Author: User
This article mainly introduces the difference between the Key quotation marks and the no quotation marks of the php array index. there is a serious difference between the quotation marks and the no quotation marks, you can refer to the following sentence when reading a PHP blog today: "If the index KEY value in PHP is not enclosed in quotation marks, the index KEY value is interpreted as a constant. if the definition of the constant cannot be found, it is interpreted as a string ". I am a bit unconvinced, because I always enclose the index KEY in quotation marks, so this is not the case. Take the time to write a line of code and test it:

The code is as follows:


Define ('webhost', 'blog ');

$ Wso = array ();

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

$ Wso ['webhost'] = 'www .bitsCN.com ';

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


Indeed, the output is www.weixiaodeyu.com instead of www.bitsCN.com. Now we know the importance of adding quotation marks to the index KEY value. If an unexpected error occurs, check it. In fact, strict execution of language specifications will not result in this difficult debugging error.

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.