Delve into php define of functions and defined of functions

  • 2020-06-07 04:07:06
  • OfStack

The define() function defines a constant.
The define() function defines a constant.
Constants are much like variables, except for the following differences:
The constant [constant] has many similarities to the variable [variable], so it is easy to confuse; Below, let's list the differences between the constant [constant] and the variable [variable] :

•A constant's value cannot be changed after it is set
1 constant value cannot be changed after specified;
•Constant names do not need a leading dollar sign ($)
When setting constants, you do not need to precede the "$" symbol;
•Constants can be accessed regardless of scope
Constants can be accessed by all scopes;
•Constant values can only be strings and numbers
Constant values can only be "string [string]" and "number [number]";

Syntax
grammar


define(name,value,case_insensitive) 

Parameter parameters Description description name Required. Specifies the name of the constant required. Specifies the name of the constant value Required. Specifies the value of the constant essential. Specifies the value of the constant case_insensitive Optional Specifies whether constant should case to TRUE, the constant case insensitive (ES75en-ES76en) optional. Specifies whether the name of the constant is case-insensitive [ES77en-ES78en]. If set to True, it is case insensitive; If set to False, it is case sensitive. The default is: False

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


<?phpdefine("GREETING","Hello you! How are you today?");echo constant("GREETING");?> 

The output of the code above will be:
The above code outputs the following results:

Hello you! How are you today? 

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

<?phpdefine("GREETING","Hello you! How are you today?",TRUE);echo constant("greeting");?> 

The output of the code above will be:
The above code outputs the following results:

Hello you! How are you today? 

The defined() function checks whether a constant exists.
The defined() function checks whether a constant exists.

Returns TRUE if the constant exists, or FALSE otherwise.
Returns True if the constant exists; If not, return False.

Syntax
grammar


defined(name) 

Parameter parameters Description description name Required. Specifies the of the constant to check necessary parameters. Specifies the name of the constant object

Example
case


<?phpdefine("GREETING","Hello you! How are you today?");echo defined("GREETING");?>  

The output of the code above will be:
The above code outputs the following results:

1 


Related articles: