您的位置:首页 > 编程语言 > PHP开发

PHP 运算符

2016-02-24 11:20 531 查看
运算符用于对值进行运算. PHP 运算符 本部分列出了在 PHP 中使用的各种运算符:
算数运算符 运算符 说明 例子 结果 + Addition x=2 x+2 4 - Subtraction x=2 5-x 3 *
Multiplication x=4 x*5 20 / Division 15/5 5/2 3 2.5 % Modulus
(division remainder) 5

运算符用于对值进行运算.


PHP 运算符

本部分列出了在 PHP 中使用的各种运算符:


算数运算符

运算符说明例子结果
+Additionx=2

x+2
4
-Subtractionx=2

5-x
3
*Multiplicationx=4

x*5
20
/Division15/5

5/2
3

2.5
%Modulus (division remainder)5%2

10%8

10%2
1

2

0
++Incrementx=5

x++
x=6
--Decrementx=5

x--
x=4

赋值运算符

运算符说明例子
=x=yx=y
+=x+=yx=x+y
-=x-=yx=x-y
*=x*=yx=x*y
/=x/=yx=x/y
.=x.=yx=x.y
%=x%=yx=x%y

比较运算符

运算符说明例子
==is equal to5==8 returns false
!=is not equal5!=8 returns true
>is greater than5>8 returns false
<is less than5<8 returns true
>=is greater than or equal to5>=8 returns false
<=is less than or equal to5<=8 returns true

逻辑运算符

运算符说明例子
&&andx=6

y=3

(x < 10 && y
> 1) returns true
||orx=6

y=3

(x==5 || y==5) returns false
!notx=6

y=3

!(x==y) returns true
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: