Definition of constants and single double quotation marks in define in php

Source: Internet
Author: User
Tags define definition
I. definition constant of define & lt ;? Phpdefine (& amp; 39; DATABASE & amp; 39;, & amp; 39; MYSQL & amp; 39;); define (& amp; 39; DATABASE_USER & amp; 39;, & amp; 39; ROOT & amp; 39;); define (& a 1. define definition constant problem Directly use the "DATABASE" constant, which represents "MYSQL ". $ Arr = array ('fruit' => 'apple', 'veggi' => 'carrot'); define ('fruit', 'veggi '); print $ arr ['fruit']; // apple print $ arr [fruit]; // carrot * Note: [] contains no quotation marks. Php will automatically parse the key value as a constant, and then find the corresponding constant in the memory, so it finds the fruit and then parses the key value. Then, find the constant in the memory and find the veggie. then, treat veggie as the real key value and find the corresponding value. Repeated quotation marks 2. single quotes error_reporting (E_ALL); $ arr = array ('fruit' => 'apple', 'veggi' => 'carrot '); define ('fruit', 'veggi'); print $ arr ['fruit']; echo'
'; // Apple print $ arr [fruit]; echo'
'; // Carrot print "hello $ arr [fruit]"; echo'
'; // Apple print "hello {$ arr [fruit]}"; echo'
'; // Hello carrot print "hello {$ arr ['fruit']}"; echo'
'; // Hello apple // print "Hello $ arr ['fruit']"; // error // print "hello $ _ GET ['foo']"; // There is an error print "Hello ". $ arr ['fruit']; // Hello apple Note: If no quotation marks are added to the array square brackets, php will resolve them by constants first.

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.