In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to define constants in php". In daily operation, I believe many people have doubts about how to define constants in php. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to define constants in php". Next, please follow the editor to study!
Php definition of constant methods: 1, the use of define () function definition, syntax "define (constant name, constant value, whether case-sensitive)"; 2, the use of const keyword definition, syntax "const constant name = constant value;"
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The method of defining constant in php
Define () function
Const keyword
Compared with variables, constants have the following characteristics:
The constant is not preceded by a dollar sign ($)
Constants can only be defined with define () and const
The scope of constants is global
Once a constant is defined, it cannot be redefined or undefined.
The define () function defines a constant
Legal constant names can only start with letters and underscores, followed by letters, numbers, or underscores of any length. You can define a constant through the define () function in PHP. The syntax of the define () function is as follows:
Define ($name, $value, $case_insensitive)
$name required parameter, constant name (need to be wrapped in double or single quotation marks)
$value required parameter, constant value
Optional parameter $case_insensitive, which specifies whether it is case-sensitive. By default, it is case-sensitive. Setting it to true indicates that it is case-insensitive.
Const keyword definition constant
Syntax:
Const constant name = constant value
Example:
The difference between define () and const:
Const defines constants at compile time, while the define () method defines constants at run time.
Const cannot be used in if statements, and defne () can be used in if statements.
If (...) {const FOO = 'BAR';// error} if (...) {define (' FOO', 'BAR'); / / correct}
A common scenario for define () is to determine whether a constant has been defined before defining a constant:
If (defined ('FOO)) {define (' FOO', 'BAR')}
When const defines a constant, the value can only be a static scalar (number, string, true,false, null), while the define () method can use the value of any expression as the value of a constant. Starting with PHP5.6, const also allows expressions to be used as constant values.
Const BIT_5 = 1
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.