Home  >  Article  >  Backend Development  >  Detailed explanation of PHP expression concepts and examples

Detailed explanation of PHP expression concepts and examples

怪我咯
怪我咯Original
2018-05-19 16:59:534831browse

What is a php expression?

Expressions are the basic elements that make up the PHP programming language, and they are also the most important component of PHP. Just like building a house, a foundation is indispensable. In PHP, almost everything written is an expression. Mode.

The most basic forms of expressions are constants and variables. For example, $a=10 means assigning the value 10 to the variable $a.

Look at a simple expression example:

$a>$b

The above is an expression. When the value of $a is greater than $b, the expression value is TRUE, otherwise it is FALSE.

Expressions are implemented through specific codes. We often use an expression to determine a value (including specific numerical values ​​and Boolean values) to do the next step. Just like the example below.

<?php
if ($a < $b) {
    echo "a< b";
}else{
    echo "a> b";
}
?>

In the above example, we used the if judgment statement. The judgment condition is the "$a b" will be output.

This is just a simple expression. In actual development, it will be much more complicated.

In addition to the simple expression above, there is also a continuous assignment expression, think of the following:

$b=$a=100

In PHP, the order of assignment operations is From right to left, so variables $b and $a are assigned the value 100.

In PHP, we use semicolon ";" to distinguish expressions and statements. Expressions can be enclosed in parentheses, as in the example above. You can simply understand it as: an expression plus a semicolon constitutes a PHP statement.

Detailed explanation of PHP expression concepts and examples Something to note here is that when we write the program, do not miss the ";" semicolon. Missing the semicolon is a common mistake made by many PHP novices.

Expressions can do many things, such as calling an array, creating a class, assigning values ​​to variables, etc.

PHP expression usage example:

<?php
$a=10;
$b=20;

if ($a < $b) {
    echo "a< b";
}else{
    echo "a> b";
}
?>

Code running result:

Detailed explanation of PHP expression concepts and examples

In the above example, $ a=10, $b=20 are expressions, and "$a

The above is the detailed content of Detailed explanation of PHP expression concepts and examples. 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