<?php
/* PHP的运算符号
*
* 运算元 运算符 运算元
*
* 1 + 1
*
* 一元运算符 +1 -1 ++ -- !
*
* 二元运算符 + - * / % > < = == ===
*
* 三元运算符 1 ? 2 : 3
*
* $a = 10;
*
* 算术运算符号 + - * / % ++ --
* 赋值运算符号 = += -= *= /= %=
* 比较运算符号 > < == >= <= === != !==
* 逻辑运算符号 && || !
* 位运算符号 & | ^ ~ >> <<
*
* 其它运算符号 ? : @ => ->
*
*/
?>
•An operator is something that takes one or more given values (an expression, in programming jargon) and produces another value (thus the entire structure becomes an expression). So think of functions or any structure that returns a value (like print) as operators, and those that don't return a value (like echo) as something else.
•There are three types of operators:
– Unary operators that operate on only one value, such as ! (the negation operator) or ++ (the addition operator).
– Binary operator, with two operands, most operators supported by PHP are of this type.
–Ternary operator: ? :.
It should be used to choose one expression between two other expressions, not to choose between two statements or program routes. It's a good idea to enclose the entire ternary expression in an expansion sign.
Operators in PHP
1. Arithmetic operators
## Common arithmetic operations Symbol
Operation type | Operator | Example | Result |
Inversion operation | - | -$a
| Return the negative value of $a |
Addition operation | + | $a + $b | Returns the sum of $a and $b |
Subtraction operation | - | $a - $b | Return $a and $ Difference of b |
Multiplication operation | * | $a * $b
##Returns the product of $a and $b |
| ##Division operation
/ |
$a / $b |
Returns the quotient of $a and $b |
| Remainder operation
% |
##$a % $b
| Return the remainder of $a and $b
|
2. Logical operators
Logical operators in PHP
##Operation type | Operator | Example | Result |
Logical and | && or and | $a && $b or $a and $b | When both $a and $b are true, return true, otherwise return false |
Logical or | || or or | $a || $b or $a or $b | When $a or $b is When true, return true, otherwise return false |
Logical XOR | xor | $a xor $b | When $a is true, $b is false or $a is false, $b is true, return true, otherwise return false |
logical negation | !
##!$a |
When $a is false, return true, otherwise return false |
|
3. Assignment operator The assignment operator "=" is the most basic operator in PHP, which assigns the value of the expression on the right side of "=" to the operand on the left. In addition, the compound assignment operator is also commonly used in PHP.
Operator
Example
Result |
|
Addition assignment
|
+=
| ##$a += 5
$a adds 5 and assigns the sum to $a |
| Subtractive assignment | -= | $a -= 5
$a minus 5 is assigned to $a |
| Multiplication assignment | *= | $a *= 5
The product of $a times 5 is assigned to $a |
| Division assignment | /= | $a /= 5
The quotient of $a divided by 5 is assigned to $a |
| The remainder is assigned | % = | $a %= 5
# The remainder of $a divided by 5 is assigned to $a |
4. Comparison operators
Operation type |
Operator |
Example |
Result |
##is less than | 040897171c6303a7dfeaaa07230d7d17 | $a > $b | when $a If the value is greater than the value of $b, it returns true, otherwise it returns false |
is less than or equal to | 1798a003a606b970d231704318bd41bf= | $a >= $b | When the value of $a is greater than or equal to the value of $b, return true, otherwise return false |
##Equal
== |
$a == $b |
When the value of $a is equal to the value of $b, it returns true, otherwise it returns false |
| Congruent
=== |
$a === $b |
When the value of $a is equal to the value of $b, and the value of $a and $b If the types are also equal, return true, otherwise return false |
|
Not equal
!= |
$a != $b or $a 6d267e5fab17ea8bc578f9e7e5e1570b $b |
When the value of $a is equal to the value of $b, it returns false, otherwise it returns true |
|
Not equal
!== |
$a !== $b |
When the value of $a is equal to the value of $b, and the types of $a and $b are also equal, return false, otherwise return true | |
|
|
The above is the detailed content of Summary of operators in php. 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