$total = 90;
switch(true){
case $total<60:
echo "不合格 <br>";
break;
case $total>60 && $total<80:
echo "合格 <br>";
break;
case $total>90:
echo "优秀 <br>";
break;
default:
echo "中等 <br>";
}
2.循环
$colors = ['red', 'green', 'blue'];
$i = 0;
while ($i < count($colors)) {
$list .= "<li>{$colors[$i]}</li>";
// 更新条件
$i = $i + 1;
}
echo 'while <br>';
echo $list.'<hr>';
$colors2 = ['red', 'green', 'blue'];
for ($i = 0; $i < count($colors); $i++) {
$list2 .= "<li>{$colors2[$i]}</li>";
}
echo 'for <br>';
echo $list2.'<hr>';
<?php
// 用二维数组来模拟数据表查询结果集
$stus = [
['id' => 1, 'name' => '刘备', 'course' => 'js', 'score' => 83],
['id' => 2, 'name' => '关羽', 'course' => 'php', 'score' => 75],
['id' => 3, 'name' => '张飞', 'course' => 'js', 'score' => 52],
['id' => 4, 'name' => '孙权', 'course' => 'php', 'score' => 88],
['id' => 5, 'name' => '周瑜', 'course' => 'js', 'score' => 65],
['id' => 6, 'name' => '孔明', 'course' => 'php', 'score' => 53],
['id' => 7, 'name' => '赵云', 'course' => 'js', 'score' => 63],
['id' => 8, 'name' => '马超', 'course' => 'js', 'score' => 77],
['id' => 9, 'name' => '姜维', 'course' => 'php', 'score' => 93],
['id' => 10, 'name' => '黄忠', 'course' => 'js', 'score' => 81],
]
<table>
<caption>学生成绩表</caption>
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>课程</th>
<th>成绩</th>
</tr>
</thead>
<tbody>
<!-- 这里显示的用户数据 -->
<?php
foreach ($stus as $stu) {
if ($stu['course'] === 'php') {
echo <<< STU
<tr>
<td>{$stu['id']}</td>
<td>{$stu['name']}</td>
<td class="active">{$stu['course']}</td>
<td>{$stu['score']}</td>
</tr>
STU;
}
}
?>
</tbody>
</table>
?>
相关推荐
© 2020 asciim码
人生就是一场修行