该如何在“ write your code here!”这里写代码,让输出结果为如下:

<html>
<body>
<?php
function calculation($para1,$para2,$operator){
// write your code here!
}
function sum($start,$end,$step){
// write your code here!
}
calculation(3,4,'add'); // do addition
calculation(3,4,'sub'); // do subtraction
calculation(3,4,'mul'); // do multiplication
calculation(3,4,'div'); // do division
sum(1,100,1);
sum(1,100,2);
?>
</body>
</html>
在“ write your code here!”这里写代码,让输出结果为:
7
-1
12
0.75
5050
2500
谢谢!

梦里花落0921
浏览 203回答 2
2回答

海绵宝宝撒

function calculation($para1,$para2,$operator){switch($operator){case 'add':return $para1+$para2;break;case 'sub':return $para1-$para2;break;case 'mul':return $para1*$para2;break;case 'div':return $para1/$para2;break;default:return false;}}function sum($start,$end,$step){$sum=0;for($i=$start;$i<=$end;$i+=$step){$sum+=$i;}return $sum;}调用函数是一个返回值,如果你想函数直接输出,那么把return 改成 echo就行了不过建议你这样调用:echo calculation(3,4,'add'); // do additionecho calculation(3,4,'sub'); // do subtractionecho calculation(3,4,'mul'); // do multiplicationecho calculation(3,4,'div'); // do divisionecho sum(1,100,1);echo sum(1,100,2);

炎炎设计

function calculation($para1,$para2,$operator){switch($operator){case 'add':return $para1+$para2;break;case 'sub':return $para1-$para2;break;case 'mul':return $para1*$para2;break;case 'div':return $para1/$para2;break;default:return false;}}function sum($start,$end,$step){$sum=0;for($i=$start;$i<=$end;$i+=$step){$sum+=$i;}return $sum;}&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP