Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
<?php
namespace _0809;
$score = 70;
// 单分支
echo '-----------------------单分支-----------------------<br>';
if ($score > 60) {
echo '通过';
}
// 双分支
echo '<br>-----------------------双分支-----------------------<br>';
$score = 50;
if ($score > 60) {
echo '通过';
} else {
echo '不通过';
}
// 双分支语法糖
echo '<br>---------------------双分支语法糖------------------<br>';
$score = 90;
echo $score > 60 ? "合格" : "不合格";
// 多分支
echo '<br>-----------------------多分支-----------------------<br>';
if ($score > 60 && $score < 70) {
echo '成绩为:B';
} elseif ($score > 70 && $score < 80) {
echo '成绩为:B+';
} elseif ($score > 80 && $score < 100) {
echo '成绩为:A';
} else {
echo '成绩为:不合格';
}
// 多分支语法糖:switch
echo '<br>------------------多分支语法糖:switch------------<br>';
switch (true) {
case $score < 60:
echo '不满意';
break;
case $score > 60 && $score < 70:
echo '满意';
break;
case $score > 80:
echo '非常满意';
break;
default:
echo '服务太差了';
}
// for循环
echo '<br>-----------------------for循环-----------------------<br>';
$title = ["语文", "数学", "几何", "英语", "地理"];
for ($i = 0; $i < count($title); $i++) {
if ($i === 1) {
continue;
}
echo $title[$i] . '<br>';
}
// foreach循环
echo '<br>-----------------------foreach循环-----------------------<br>';
foreach ($title as $k => $v) {
printf('序号:%s ---> 书名:%s<br>', $k, $v);
}
// while循环
echo '<br>-----------------------while循环-----------------------<br>';
$i = 0;
while ($i < count($title)) {
echo $title[$i] . '<br>';
$i++;
}
<?php
namespace _0809;
$cs = [
['id' => '第一节', 'name' => '覃老师', 'sex' => 0, 'course' => '语文'],
['id' => '第二节', 'name' => '覃老师', 'sex' => 0, 'course' => '语文'],
['id' => '第三节', 'name' => '张老师', 'sex' => 1, 'course' => '数学'],
['id' => '第四节', 'name' => '孙老师', 'sex' => 1, 'course' => '几何'],
['id' => '第五节', 'name' => '周老师', 'sex' => 1, 'course' => '地理'],
['id' => '第六节', 'name' => '孔老师', 'sex' => 0, 'course' => '英语'],
['id' => '第七节', 'name' => '赵老师', 'sex' => 1, 'course' => '体育'],
['id' => '第八节', 'name' => '马老师', 'sex' => 0, 'course' => '美术'],
]
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>课程表</title>
<style>
table {
border-collapse: collapse;
width: 360px;
text-align: center;
}
table th,
table td {
border: 1px solid #000;
padding: 5px;
}
table caption {
font-size: 1.3em;
}
table thead {
background-color: lightcyan;
}
.active {
color: red;
}
</style>
</head>
<body>
<table>
<caption>20班课程表</caption>
<thead>
<tr>
<th>节名</th>
<th>教师</th>
<th>性别</th>
<th>课程</th>
</tr>
</thead>
<tbody>
<?php
foreach ($cs as $cso) : ?>
<tr>
<td><?= $cso['id'] ?></td>
<td><?= $cso['name'] ?></td>
<td><?= $cso['sex'] ? '男' : '女' ?></td>
<td><?= $cso['course'] ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
</body>
</html>