批改状态:合格
老师批语:
if (XXX){echo 'XXXXX';}
单分支就是以if,填充条件,从而返回结果
if ($age >= 18){echo '已成年,可以观看<br>';}else{echo '未成年,请在父母陪同下观看 <br>';}
双分支和单分支 不同的地方在于,多了一个else ,从而判断输出不同的内容,如果是满足则输出if。不满足的情况下,输出else
switch (true){case $age >= 18 && $age < 30;echo "{$age}岁,可以按揭?<br>";break;case $age >= 30 && $age < 45;echo "{$age}岁,可以按揭?<br>";break;default;echo "{$age}放学送你回家<br>";}

$colors = ['red', 'green', 'blue'];$i = 0;$list = '<ul style="border:1px solid red">';if ($i < count($colors)){$list .= "<li>{$colors[$i]}</li>";}//$i += 1;$i++;if ($i < count($colors)){$list .= "<li>{$colors[$i]}</li>";}$i++;if ($i < count($colors)){$list .= "<li>{$colors[$i]}</li>";}$list .= '</ul>';echo $list;

<?php$aoyun = [['id' => 1, 'name' => '中国', 'score' => 83],['id' => 2, 'name' => '法国', 'score' => 75],['id' => 3, 'name' => '德国', 'score' => 52],['id' => 4, 'name' => '英国', 'score' => 88],['id' => 5, 'name' => '美国', 'score' => 65],['id' => 6, 'name' => '俄罗斯', 'score' => 53],['id' => 7, 'name' => '日本', 'score' => 63],['id' => 8, 'name' => '奥大利亚', 'score' => 77],['id' => 9, 'name' => '西班牙', 'score' => 93],['id' => 10, 'name' => '越南', 'score' => 41],]?>
<?phpforeach($aoyun as $ay) : ?><tr><?php if ($ay['score'] >= 70) : ?><td><?=$ay['id']?></td><td><?=$ay['name']?></td><td><?=$ay['score']?></td><?php endif ?></tr><?php endforeach ?>

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号