A brief discussion on operators and operator priority tutorials in php

伊谢尔伦
Release: 2023-03-10 21:56:01
Original
1296 people have browsed it

1.Arithmetic operator

## %: Modulo operation (remainder operation)

/ : Division operation (the result is the value of the quotient)
Note: The divisor 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)
?>
Copy after login

2.String operatorThere is only one string operator in PHP, that 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.岁";
?>
Copy after login

3. Assignment operator: Operate the value on the left and your value on the right and assign it to the left .= Meaning: Connect the variable to the assigned value The result is assigned to the variable
Example: $x.=3 Equivalent to $x=$x."3"

4.Comparison operator: two Meta-operator The difference between “=", “==” and “===”
“=": is an assignment symbol
“==”: is an equal No., when the operand on the left is equal to the operand on the right, TRUE is returned, otherwise FALSE
is returned. "===": When the operand on the left is the same as the operand on the right, and their data types are also the same Returns TRUE                                                                                                                                                                                                                                                                                              When the operand is TRUE, it returns TRUE
or or ||: When the operands on both sides are FASE, it returns FALSE not or!: When the operand is TRUE, it returns FALSE xor: Logic AND or operation, as long as the operand on one side is TRUE, it can return TRUE
6. Bit operators: &: Two 1s are 1; | : Two 0s are considered 0;
^ : When the two operands are different, the value 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.岁";
    ?>
Copy after login

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 A brief discussion on operators and operator priority tutorials in php. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template