运算符
说明
例子
=
x=y
x=y
+=
x+=y
x=x+y
-=
x-=y
x=x-y
*=
x*=y
x=x*y
/=
x/=y
x=x/y
.=
x.=y
x=x.y
%=
x%=y
x=x%y
比较运算符
运算符
说明
例子
==
is equal to
5==8 returns false
!=
is not equal
5!=8 returns true
>
is greater than
5>8 returns false
<
is less than
5<8 returns true
>=
is greater than or equal to
5>=8 returns false
<=
is less than or equal to
5<=8 returns true
逻辑运算符
运算符
说明
例子
&&
and
x=6
y=3
(x < 10 && y > 1) returns true
||
or
x=6
y=3
(x==5 || y==5) returns false
!
not
x=6
y=3
!(x==y) returns true
11、if、elseif
以及 else 语句用于执行基于不同条件的不同动作。
实例
如果当前日期是周五,下面的例子会输出 "Have a nice weekend!"
,如果是周日,则输出 "Have a nice Sunday!"
,否则输出 "Have a nice
day!":
<html>
<body>
<?php
$d=date("D"); //获取时间
if ($d=="Fri") //当时间相等时
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
</body>
2