Home  >  Article  >  Backend Development  >  How to quickly learn PHP operators in one day (detailed introduction)

How to quickly learn PHP operators in one day (detailed introduction)

慕斯
慕斯Original
2021-06-02 17:46:471912browse

The previous article introduced you to "Selected flow control statements--break statement and continue statement (with detailed explanation) ". This article continues to introduce to you how to quickly understand PHP in one day (detailed introduction), I believe you will definitely make new discoveries and gains, come on, let’s explore together!

How to quickly learn PHP operators in one day (detailed introduction)

l Logical operator:

Concept:

Perform logical operations on expressions to calculate The result is a Boolean type value (true, false)

Requirements:

The value of the expression participating in the logical operation is a Boolean type value. If not, it will be blocked by PHP Automatically converted into a Boolean value

(1) Logical AND and or &&

When the values ​​of the left and right expressions are both true, the operation result is true, and vice versa. As long as one of them is false, the operation result is false;

The following values ​​will be considered false, and other values ​​will be considered true

①Boolean value false

② 0

③ Floating point type 0.0

④ Blank string and string 0

⑤ Array with no members

⑥ null

(2) Logical OR or or ||

If one of the values ​​of the expressions on the left and right sides is true, the result of the operation is true. Only when the values ​​on both sides are false, the result is false

(3) Logical exclusive OR The value of the expression is negated. It used to be false and now it is true, and vice versa.

l Other operators

(1)Ternary operator? :

Expression 1?Expression 2:Expression 3;If the value of expression 1 is true, then execute expression 2, otherwise execute expression 3

( 2) ` `operator

can put system commands in it for execution (involving cross-platform)

(3)@operator

The shielding expression may cause errors

(4)

(5)

(6)

l Operator precedence

Use Parentheses can treat a certain part of the expression as a whole

1. Using parentheses can enhance the readability of the code2. Some places do not need to add parentheses, but you can also add them. , Increase the readability of statements

Short-circuit problem

Programming language designers believe that as long as there are logical operators (logical AND, logical OR), the result of the operation is true or false, the running process is not important

$a=false;
$b=1;
$a && ++$b;
Echo $b;//短路,上面的++$b被短路了,结果还是1

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to quickly learn PHP operators in one day (detailed introduction). 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