Blogger Information
Blog 87
fans 0
comment 0
visits 59373
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
第三章:4.流程控制:条件判断
黄忠倚的博客
Original
538 people have browsed it

实例

<?php
echo '<h3>4.流程控制:条件判断</h3>';
echo '<hr color="orange">';

//1.单分支
$grade = 55;
if ($grade < 60) {
	echo '<p style="color:red">很不幸,您得补考!</p>';
}

echo '<hr color="red">';


//2.双分支
$grade = 60;
if ($grade <60) {
	echo '<p style=color:red">很不幸,您得补考!</p>';
} else {
	echo '<p style="color:green">恭喜,您及格了!</p>';
}
echo '<hr color="green">';
echo '<hr color="green">';

//3.多分支
$grade =90;
if ($grade <60) {
	echo '<p style=color:red">很不幸,您得补考!</p>';
} elseif ($grade >=60 && $grade <=80){
	echo '<p style="color:green">哎哟,考得还不错哦!</p>';
} elseif ($grade >=80 && $grade <=100){
	echo '<p style="color:green">厉害,你真是个天才!</p>';
}
echo '<hr color="green">';
echo '<hr color="seagreen">';


//4.三元运算符:双分支的简化
$grade =55;
// echo ($grade <60) ? '<p style="color:red">你的智商让人捉急啊!</p>' : '<p style="color:green">恭喜,您及格了!</p>';
// 简化:
echo $grade <60 ? '<p style="color:red">你的智商让人捉急啊!</p>' : '<p style="color:green">恭喜,您及格了!</p>';

echo $grade>60 ? '你的智商让人捉急啊!' : '恭喜,您及格了!';
echo '<hr color="orange">';

//5.switch()
$program = 'php';
//$program = 'java';
//$program = 'abc';
//
switch ($program) {
	case 'php':
		echo '<p>php是世界上最好的语言吗?</p>';
		// break;  //如果想每个分支单独运行,break是不能省略的!

	case 'java':
		echo '<p>java是纯面向对象的编程语言!</p>';
		break;

	default:
		echo '<p>您所关心的课程,我们正在录制中。。。</p>';
		break;
}

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post