PHP语句

PHP条件语句

if语句

1
2
3
4
5
6
7
<?php 
$t=date("H");
if ($t<"20")
{
echo "Have a nice day!";
}
?>

if…else 语句

1
2
3
4
5
6
7
8
9
10
11
12

<?php
$t=date("H");
if ($t<"20")
{
echo "Have a good day!";
}
else
{
echo "Have a good night!";
}
?>

if…elseif…else 语句

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

<?php
$t=date("H");
if ($t<"10")
{
echo "Have a good morning!";
}
elseif ($t<"20")
{
echo "Have a good day!";
}
else
{
echo "Have a good night!";
}
?>

PHP Switch语句

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php 
$favcolor="red";
switch ($favcolor)
{
case "red":
echo "你喜欢的颜色是红色!";
break;
case "blue":
echo "你喜欢的颜色是蓝色!";
break;
case "green":
echo "你喜欢的颜色是绿色!";
break;
default:
echo "你喜欢的颜色不是这三个!";
}
?>

#输出结果:
#你喜欢的颜色是红色!