PHP define constant definition and variable difference _php tutorial

Source: Internet
Author: User
Tags constant definition php define variable scope
Constants must be defined before they are used, or the program execution will fail. Use the Define () function in the PHP tutorial to define constants.

1. Syntax format: define ("Constant name", "Constant value");

For example: Define ("php360", "Perfect php");


Here's an example:

The Define () function defines a constant.

Constants are similar to variables, except that:

After setting, the value of the constant cannot be changed
Constant name does not need to start with dollar sign ($)
Scope does not affect access to constants
A constant value can only be a string or a number
Grammar
Define (name,value,case_insensitive) parameter description
Name is required. Specifies the name of the constant.
Value is required. Specifies the value of the constant.
Case_insensitive required. Specifies whether the name of the constant is case sensitive.

If set to true, the case is not sensitive. The default is False (case sensitive).
*/


Define ("greeting", "Hello world!");
ECHO constant ("greeting");


/*
Running this code will output hello world! in the browser. The result.

2, the constant naming rules: start with a letter or underscore, followed by any letter, number, underline.

3. The difference between constant and variable:

(1) A constant is preceded by a $ symbol, and the variable must begin with a $ symbol.

(2) Constants can only be defined with the Define () function and cannot be defined by an assignment statement.

(3) Constants can be defined and accessed anywhere, regardless of the rules of the variable scope.

(4) Once a constant is defined, it cannot be redefined or de-defined, and the value cannot be changed, and the value of the variable can change at any time.

(5) The value of a constant can only be scalar, that is, integer, float, string 3 types */

http://www.bkjia.com/PHPjc/632320.html www.bkjia.com true http://www.bkjia.com/PHPjc/632320.html techarticle constants must be defined before they are used, or the program execution will fail. Use the Define () function in the PHP tutorial to define constants. 1, Syntax format: Define (constant name, constant value); For example: ...

  • 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.