In PHP, define defines constants and single double quotes.

Source: Internet
Author: User
Tags define array constant key mysql
First, define define constant issues        <?php   define (' DATABASE ', ' MYSQL ');   Define (' Database_user ', ' ROOT ');   Define (' Database_password ', ' PASSWORD ');  ?>                 Direct use of "DATABASE" constant, represents "MYSQL".                 $arr = array (' Fruit ' => ' apple ', ' veggie ' => ' carrot ');                define (' fruit ', ' veggie ');                            print $arr [' Fruit '];  // apple              print $arr [fruit];  // carrot               * Note: There are no quotes in []. PHP automatically resolves the key value as a constant, then goes to the memory to find the corresponding constant, and then finds the fruit and then resolves the key value. Then go to the memory to find the constant, did not find veggie, and then the veggie as a real key value, find the corresponding value.                 second, single double quotes problem       error_reporting (E_all);       $arr = Array (' Fruit ' => ' apple ', ' veggie ' => ' carrot ');       define (' fruit ', ' veggie ');     Print $arr [' fruit ']; Echo ' <br/> ';    //apple     print $arr [fruit]; Echo ' <br/> ';    //carrot     print "Hello $arr [fruit]"; Echo ' <br/> ';  //Apple     print "Hello {$arr [fruit]}"; Echo ' <br/> '; Hello Carrot     print "Hello {$arr [' Fruit ']}";  echo ' <br/> '/hello Apple    //print "Hello $arr [' fruit ']"; There are errors    //print "Hello $_get[' foo ']"; There are errors    print "Hello". $arr [' Fruit ']; Hello Apple   Note: If the array square brackets are not enclosed in quotes, PHP will first parse by constants.

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.