PHP functions define () and defined ()

Source: Internet
Author: User
ArticleDirectory
    • Example 1
    • Example 2

Define () Definition and usage:

The define () function defines a constant.

Constants are similar to variables, except that:

    • After setting, the constant value cannot be changed.
    • The constant name does not need to start with the dollar sign ($)
    • The scope does not affect constant access.
    • A constant value can only be a string or number.

Syntax:

 
Define (name, value, case_insensitive)
Parameters Description
Name Required. Specifies the name of a constant.
Value Required. Specifies the value of a constant.
Case_insensitive

Required. Specifies whether the constant name is case sensitive.

If it is set to true, it is not case sensitive. The default value is false (case sensitive ).

Example 1

Defines a case-sensitive constant:

<?PHPDefine("Greeting", "Hello world! ");Echo Constant("Greeting");?>

Output:

 
Hello world!
Example 2

Defines a case-insensitive constant:

 
<?PHPDefine("Greeting", "Hello world! ",True);Echo Constant("Greeting");?>

Output:

Hello world!

**************************************** **************************************** **************************************** ********************


Defined () Definition and usage:

The defined () function checks whether a constant exists.

If a constant exists, true is returned; otherwise, false is returned.

Syntax:

 
Defined (name)

Parameters Description
Name Required. Specifies the name of the constant to be checked.
 


Example:
<?PHPDefine("Greeting", "Hello world! ");Echo Defined("Greeting");?>

Output:

 
1
   
   

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.