分支判断
// '单分支';
$age = 17;
if($age<18){
echo '未成年';
};
echo '<hr>';
$age = 20;
//双分支
if($age<18){
echo '未成年';
}else{
echo '成年啦';
}
echo '<hr>';
//多分支
$age = 50;
if($age<18){
echo '未成年';
}elseif($age<40){
echo '成年人';
}else{
echo '老年人';
}
echo '<hr>';
//语法糖
//双分支语法糖 三元运算符
echo $age<18 ? '未成年' : '成年了';
echo '<hr>';
//多分支语法糖switch
$age = 70;
switch(true){
case $age>18 && $age<=30:
echo '年轻人';
break;
case $age>30 && $age<=60:
echo '中年人';
break;
case $age>60:
echo '老年人';
break;
default:
echo '未成年';
};
循环输出模板
$shuju =[
['id'=>1,'name'=>'安邦','age'=>18,'order'=>1, 'score'=>59 ],
['id'=>2,'name'=>'安福','age'=>18,'order'=>2, 'score'=>42 ],
['id'=>3,'name'=>'安歌','age'=>18,'order'=>3, 'score'=>61 ],
['id'=>4,'name'=>'安国','age'=>18,'order'=>4, 'score'=>73 ],
['id'=>5,'name'=>'安和','age'=>18,'order'=>5, 'score'=>89 ],
['id'=>6,'name'=>'安康','age'=>18,'order'=>6, 'score'=>46 ],
['id'=>7,'name'=>'安澜','age'=>18,'order'=>7, 'score'=>65 ],
['id'=>8,'name'=>'安民','age'=>18,'order'=>8, 'score'=>62 ],
['id'=>9,'name'=>'安宁','age'=>18,'order'=>9, 'score'=>52 ],
['id'=>10,'name'=>'安平','age'=>18,'order'=>10,'score'=>55],
['id'=>11,'name'=>'安然','age'=>18,'order'=>11,'score'=>88],
['id'=>12,'name'=>'安顺','age'=>18,'order'=>12,'score'=>60]
];
<body>
<table>
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>年龄</th>
<th>学号</th>
<th>成绩</th>
</tr>
</thead>
<tbody>
<?php foreach($shuju as $v) : ?>
<tr>
<?php if($v['score']>=60):?>
<td><?php echo $v['id']?></td>
<td><?php echo $v['name']?></td>
<td><?php echo $v['age']?></td>
<td><?php echo $v['order']?></td>
<td><?php echo $v['score']?></td>
<?php endif?>
</tr>
<?php endforeach ?>
</tbody>
</table>
</body>
本文来自投稿,不代表本站立场,如若转载,请注明出处:https://www.hui-xiang.cn/archives/178.html