Collection of php operators

小云云
Release: 2023-03-20 14:58:02
Original
1523 people have browsed it

Everyone will come into contact with operators when learning programming languages. This article mainly shares with you a collection of PHP operators, hoping to help everyone.

1. Operator precedence
Increment/Decrease> ! > Arithmetic operators> Size comparison> (Not)Equality comparison> Reference>
Bit operator (^ ) > bit operator (|) > logical AND > logical OR > ternary > assignment > and > Use

2. Comparison operators
2.1, the difference between == and ===
==: Comparison value
===: Comparison value and comparison type

2.2. Judgment of equality (seven cases of FALSE)
0, 0.0, ' ', '0', false, array(), null

2.3. Increasing and decrementing does not affect the Boolean value

2.4. Decreasing the NULL value has no effect, but increasing the NULL value is 1

3. Logical operators
3.1. Short-circuit effect
$a = true || $b == 3 ;//$b is not executed
$b = false && $a == 1;//$a is not executed

3.2, || and && have different priorities from or and and
&& > || > and > or

$a = false || true; //true
$b = false or true; // false



4. Example

 0 || $b = 3 > 0) * { * $a++; * $b++; * echo $a. "\n"; * echo $b. "\n"; * } */ $a = 0; $b = 0; if ($a = 3 > 0 || $b = 3 > 0) { /** * > 的优先级大于 || 大于 = * 因此可以认为是 * $a = ((3 > 0) || $b = 3 > 0) * => $a = (true || $b = 3 > 0) * 由于逻辑或短路作用,b 不再执行 * 因此:$a = true, b = 0 * 由于布尔值递增和递减都不影响还是true,而打印echo时,true底层转为1 * 因此最终echo a 和 b,都是1 */ $a++; $b++; echo $a. "\n"; echo $b. "\n"; }
Copy after login

Related recommendations:


Simple questions about PHP operator priority

##PHP Examples of operators

Detailed explanation of php operators and expression usage examples

The above is the detailed content of Collection of php operators. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!