Declaration and use of PHP constants

Source: Internet
Author: User
Tags php define
Declaration and use of PHP constants

Constants can be understood as values unchanged, constants are defined and cannot be changed anywhere else in the script, a constant consists of an English letter, an underscore, and a number, but the number cannot be used as the first letter of a constant.

Use the # define () function in PHP to define constants, which are syntactically formatted as follows:

Define (string constant_name,mixed value,case_sensitive=true)


There are two ways to get the value of a constant, one is to get the value directly using the name of the constant, the second is to take advantage of the constant () function, the second is to use the constant () function and the effect of the output directly using the constant name, but the function can dynamically output the values of different constants, This is much more flexible and convenient.

The first gets its value directly with the name of the constant

 
  

The results of the operation are as follows:


The second use of the constant () function to get the value code for the constant is as follows:

 
  

The results of the operation are as follows:


Then let's talk about the case-sensitive problem, just the declaration of the constant is case-sensitive, we use the code to verify the see is not, in addition to enhance my memory


The code is as follows:

 
  

Let's look at the results of the output again.



You can find that the settings are not sensitive to case, even if the case is different, but the output is still the same.


The predefined constants are the same as the constants we define ourselves, with the usual predefined constants:














  • Related Article

    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.