Explore the use of PHP define () function and defined () _php techniques

Source: Internet
Author: User
Tags constant php define

The Define () function defines a constant.
The purpose of the Define () function is to define a constant.

Constants are much like variables, except for the following differences:
constants [constant] have a lot in common with variables [variable], so it's easy to confuse; below, we enumerate the differences between the constants [constant] and the variable [variable]:
A constant ' s value cannot be changed the It is set
A constant value cannot be changed after it has been specified;
Constant names do not need a leading dollar sign ($)
When you set a constant, you do not need to precede the "$" symbol;
Constants can be accessed regardless of scope
Constants can be accessed by all ranges of domains;
Constant values can only be strings and numbers
The value of a constant can only be "string" and "digit [number]";

Syntax
Grammar
Define (name,value,case_insensitive)

Parameter
Parameter
Description
Describe
Name Required. Specifies the name of the constant
Necessary parameters. Specify the name of the constant
Value Required. Specifies the value of the constant
Necessary parameters. Specifying the value of a constant
Case_insensitive Optional. Specifies whether the constant name should be case-insensitive. If set to TRUE, the constant would be case-insensitive. Default is FALSE (case-sensitive)
Optional parameters. Specifies whether the name of the constant is case-insensitive [case-insensitive]. If set to True, the letter is case-insensitive, and if set to false, the case is case-sensitive. The default value is: False

Example 1
Case 1
Define a case-sensitive constant:
Specify a constant (case-sensitive):

Copy Code code as follows:

<?phpdefine ("Greeting", "Hello you! How to Are you today? "); ECHO constant ("greeting");? >

The output of the code above would be:
The above code will output the following result:
Copy Code code as follows:

Hello you! How are are you today?

Example 2
Case 2
Define a case-insensitive constant:
Specify a constant (case-insensitive):
Copy Code code as follows:

<?phpdefine ("Greeting", "Hello you! How to Are you today? ", TRUE); Echo constant (" greeting ");? >

The output of the code above would be:
The above code will output the following result:
Copy Code code as follows:

Hello you! How are are you today?

The defined () function checks whether a constant exists.
the defined () function is to check whether a constant exists.

Returns TRUE If the constant exists, or FALSE otherwise.
Returns true if the constant exists, or false if it does not exist.
Syntax
Grammar

Copy Code code as follows:

Defined (name)

Parameter
Parameter
Description
Describe
Name Required. Specifies the name of the constant to check
Necessary parameters. Specifies the name of a constant object

Example
Case

Copy Code code as follows:

<?phpdefine ("Greeting", "Hello you! How to Are you today? "); echo defined ("greeting");? >

The output of the code above would be:
The above code will output the following result:
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.