时间:2021-07-01 10:21:17 帮助过:4人阅读
- $x = 100;$y = 0;switch($x) { case $x > 600: $y += *$x - 600)* 0.91; $x = 600; case $x > 260: $y += ($x - 260)* 0.66; $x = 260; default: $y += $x * 0.61;}echo $y;
根据不同条件执行不同的处理,使用switch语句就可以了。
这和小学时候写的算术计算表达式差不多,只是要运用php来写而已。
- function fee($el, & $fee){
- switch ($el){
- case $el > 600:
- $fee += ($el-600)*0.91+fee(600, $fee);
- break;
- case $el > 260:
- $fee += ($el-260)*0.66+fee(260, $fee);
- break;
- default:
- $fee += $el*0.61;
- break;
- }}fee(800, $fee);echo $fee;