In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about the differences between variables and constants in php. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Differences: 1. Constants can only be defined by the define () function or const keyword, while keywords or functions that are not defined by variables are defined when assigning values. 2. The variable name is prefixed with "$", but the constant name is not needed. 3. The value of variable can be changed, but the value of constant can not. 4. Variables have global and local scope, while constants have only global scope.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
What is the php constant?
The so-called constant is a quantity that cannot be changed. Once a constant is defined in PHP, it cannot be modified or undefined.
PHP constants are usually used to store data that is neither changed nor desired, which can only be data of four scalar data types: integer, floating-point, string, and Boolean, but the constant supports array since PHP7.
The difference between constant and variable in php
Define it in different ways:
Php variables have no defined keywords or functions and are defined when assigning values. The php constant can only be defined with the define () function or the const keyword.
The name is different:
The php variable name needs to be decorated with a dollar sign ($), while the php constant name is not required. The constant is not preceded by a dollar sign ($). Php variable names are recommended to be lowercase. When composed of multiple words, the first letter of the first word is lowercase and the rest are capitalized. Php constant names are recommended to be all uppercase.
Values have different meanings:
The value stored in the php variable can be changed, while the value stored in the php constant cannot be changed.
Scope does not need to:
Php variables have global scope and local scope. Php constants are generally defined outside all functions, and the scope of constants is global.
The data type ranges are different:
Php variables can be of any data type, while php constants can only be scalar types (integer, float/double, string, boolean).
Thank you for reading! This is the end of this article on "what is the difference between variables and constants in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.