Home  >  Article  >  Backend Development  >  Can PHP constants be expressions?

Can PHP constants be expressions?

尚
Original
2019-10-30 14:16:483578browse

Can PHP constants be expressions?

Expressions are the most important cornerstone of PHP. In PHP, almost everything you write is an expression . The simple but most precise way to define an expression is "anything with a value".

The most basic expression forms are constants and variables. When typing "$a = 5", the value "5" is assigned to the variable $a. "5", obviously, has the value 5, in other words "5" is an expression with the value 5 (here, "5" is an integer constant).

After the assignment, the expectation is that the value of $a is 5, so if we write $b = $a, the expectation is that it will be the same as $b = 5. In other words, $a is an expression that also evaluates to 5. If everything works correctly, this is exactly what is going to happen.

Some expressions can be treated as statements. At this time, the form of a statement is 'expr' ';', that is, an expression ends with a semicolon. In "$b=$a=5;", $a=5 is a valid expression, but it is not a statement in itself. "$b=$a=5;" is a valid statement.

Recommended: php server

The above is the detailed content of Can PHP constants be expressions?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php check if onlineNext article:php check if online