$a
";//Output value 1 var_dump($a);//Type of data that can be output: int (1)?>"/> $a";//Output value 1 var_dump($a);//Type of data that can be output: int (1)?>">Home >Backend Development >PHP Tutorial >Example explanation of PHP operators
1. Arithmetic operators:
%: Modulo operation (remainder operation)
/: Division operation (the result is the value of the quotient)
Note: The divisors of the above two operations cannot be 0. In PHP language, the operands on both sides of % will be converted to integers before the operation.
Example:
<?php $a=10%3; echo "<p>$a</p>";//输出数值1 var_dump($a);//可以输出数据的类型:int(1)?>
##2. String operator in PHP There is only one string operator in English, which is the English period (.), also known as the connection operator
If you are connecting a variable, you need to add (.) on both sides of the variable and add "" on the outside
Example:
<?php header("Content-type:text/html;charset=utf-8"); $name="吴彦祖"; $age=30; $adress="中华民族共和国"; echo "<p>我的名字:".$name.",</p><p>我来自".$adress."。</p>"."<br>今年$age.岁"; ?>
3. Assignment operator: Operate the value on the left and your value on the right and assign it to the left .=
## 4. Comparison operators: Denta computers
# This, "==", "===" the differences " =”: It is an assignment symbol “==”: It is an equal sign. When the operand on the left is equal to the operand on the right, TRUE is returned, otherwise it returns FALSE “===”: When the operand on the left The operands are the same as the operands on the right, and their data types are also the same before TRUE
5. Logical operators: used to determine right or wrong
and or &&: TRUE is returned only when the operands on both sides are TRUE or or ||: operands on both sides When it is FASE, it returns FALSE not or!: When the operand is TRUE, it returns FALSE xor: Logical AND or operation, as long as one side of the operand is TRUE, it can return TRUE
6. Bit operators:
&: Two 1s are 1; |: Two 0s are 0; ^ : When the two operands are different, it is 1 Example:
<?php header("Content-type:text/html;charset=utf-8"); $name="吴彦祖"; $age=30; $adress="中华民族共和国"; echo "<p>我的名字:".$name.",</p><p>我来自".$adress."。</p>"."<br>今年$age.岁"; ?>
7.三元运算符:(exprl)?(exprl1):(exprl2)类似与 “if...else”,但是三元运算符会显得更加的整洁
当experl的值为TRUE时,获取exprl1 的值,反之 取exprl2的值
8.执行运算符 :反引号‘ ’
PHP将尝试将引号的内容作为操作系统命令来执行,并将其输出信息返回
9.错误输出控制符号:@
将其放在一个PHP表达式之前,产生的任何警告信息都将被忽略,它只对表达式有效。
规则:如果能从某处取到值,就可以在它的前面加上@。不能放在函数和类的定义之前。
10.运算符的优先级
优 先 级 结合方向 运 算 符 附加信息
1 非结合 new new
2 左 [ array()
3 非结合 ++ -- 递增/递减运算符
4 非结合 ! ~ - (int) (float) (string) (array) (object) @ 类型
5 左 * / % 算数运算符
6 左 + - . 算数运算符和字符串运算符
7 左 << >> 位运算符
8 非结合 < <= > >= 比较运算符
9 非结合 == != === !== 比较运算符
10 左 & 位运算符和引用
11 左 ^ 位运算符
12 左 | 位运算符
13 左 && 逻辑运算符
14 左 || 逻辑运算符
15 左 ? : 三元运算符
16 右 = += -= *= /= .= %= &= |= ^= <<= >>= 赋值运算符
17 左 and 逻辑运算符
18 左 xor 逻辑运算符
19 左 or 逻辑运算符
20 左 , 多处用到
The above is the detailed content of Example explanation of PHP operators. For more information, please follow other related articles on the PHP Chinese website!