Introduction to the use of operators in PHP development

韦小宝
Release: 2023-03-17 17:08:01
Original
1562 people have browsed it

PHP has a rich set of operators. PHP operators are also often used. PHP operators are distinguished according to different functions. Operators can Divided into: arithmetic operator, string operator, assignment operator, bit operator, conditional operator, and logical operatorwait. Okay, let’s take a look at the PHP operator!

When various operators are in the same expression, their operations have a certain priority.

(1) Arithmetic operation

+ - * / % ++ –

(2) String operator

There is only one string operator. (dot) is the English period. It can concatenate strings to form a new string, or it can concatenate strings with numbers, and the types will be automatically converted.

$a="dawanganban"; 
$b="123"; 
echo $a.$b;   //输出结果:dawanganban123
Copy after login

(3) Assignment operator

= += -= *= /= %= .=

$a="dawanganban"; 
$a.=1; 
$a.=2; 
$a.=3; 
echo $a.$b;   //输出结果:dawanganban123
Copy after login


(4) Bit operator

& | ~ ^ << >>

(5)Comparison operator##> < > ;= <= == != <> === !==

<>: is not equal to sum! =Same

===: Identity, equal values ​​and consistent types

! ==: non-identity, unequal values ​​or inconsistent types

echo 5 == "5"; //true  PHP是弱类型语言(js中的变量类似)
echo 5 === "5";  //false  完全等于
Copy after login

(6) Logical operations

AND (logical AND) OR (logical OR) XOR (logical exclusive OR) && (logical AND) || (logical OR) ! (logical NOT)

var_dump(5 && "");   //false 
var_dump(5 && "2"); //true 
var_dump(5 || ""); //true 
var_dump(0 xor 1); //true 
var_dump(0 xor 0); //false 
var_dump(1 xor 1); //false
Copy after login

The above is all the introduction to the use of operators in PHP development. I hope it will be of great help to the students.

Related recommendations:

Simple questions about PHP operator priority

Examples of PHP operators

Basic introduction to PHP operators

The above is the detailed content of Introduction to the use of operators in PHP development. 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