批改状态:合格
老师批语:写的还行!可以多加点文字说明,另外标题注意一下!
$amount = 1000;$payment = $amount;if ($amount >= 500) :$payment = $amount * 0.9;endif;echo '实际支付:', $payment, '<br>';
$amount = 400;if ($amount >= 500) :$payment = $amount * 0.9;else :$payment = $amount;endif;echo '实际支付:', $payment, '<br>';
$amount = 3000;if ($amount >= 1000 && $amount < 1500) :$payment = $amount * 0.9;elseif ($amount >= 1500 && $amount < 2000) :$payment = $amount * 0.8;elseif ($amount >= 2500) :$payment = $amount * 0.7;else :$payment = $amount;endif;echo '实际支付:', $payment, '<br>';
$amount = 500;switch (true) {case $amount >= 1000 && $amount < 1500:$payment = $amount * 0.9;break;case $amount >= 1500 && $amount < 2000:$payment = $amount * 0.8;break;case $amount >= 2500:$payment = $amount * 0.7;break;default:$payment = $amount;}echo '实际支付:', $payment, '<br>';
$discount = 0.8;$amount = 3300;switch ($discount):case 0.7:$payment = $amount * 0.7;break;case 0.8:$payment = $amount * 0.8;break;case 0.9:$payment = $amount * 0.9;break;default:$payment = $amount;endswitch;echo '实际支付:', $payment, '<br>';
$cities = ['北京', '深圳', '广州', '天津', '上海'];while ($city = current($cities)) {echo $city, '<br>';next($cities);}
怎么才能再次循环,必须指针复位
reset($cities);while ($city = current($cities)) :echo $city, '<br>';next($cities);endwhile;
2.判断型循环,出口判断型 do (…) while(条件)
3.计数型循环:for(循环变量初始化,循环条件,更新循环条件){…}
do {echo $city, '<br>';next($cities);} while ($city = current($cities));
for ($i = 0; $i < count($cities); $i++) {echo $cities[$i], '<br>';}echo '<hr>';for ($i = 0; $i < count($cities); $i++) :echo $cities[$i], '<br>';endfor;
for ($i = 0; $i < count($cities); $i++) :if ($i > 1) break;echo $cities[$i], '<br>';endfor;
for ($i = 0; $i < count($cities); $i++) :if ($i === 2) continue;echo $cities[$i], '<br>';endfor;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号