即时通讯对PHP很新颖,希望有人能帮助我。我需要写一个类,当下面的页面回响时,它会显示答案。在PHP中添加参数PHP
<?php
include_once('Math.php');
$Math = new _Math();
echo $Math->calculate(2,3,"+")."<br />";
echo $Math->calculate(2,3,"-")."<br />";
echo $Math->calculate(2,3,"*")."<br />";
echo $Math->calculate(9,3,"/")."<br />";
echo $Math->calculate(9,0,"/")."<br />";
echo $Math->calculate("3",3,"+")."<br />";
echo $Math->calculate(2.5,3,"+")."<br />";
echo $Math->calculate(3,3,"test")."<br />";
我认为下面的代码可以工作,但即时通讯除了空白的屏幕上什么都没有。
<?php
class _Math {
function calculate(2,3,"+"){
$x = 2 + 3;
return $x;
}
function calculate(2,3,"-"){
$x = 2 - 3;
return $x;
}
function calculate(2,3,"*"){
$x = 2 * 3;
return $x;
}
function calculate(9,3,"/"){
$x = 9/3;
return $x;
}
function calculate(9,0,"/"){
$x = 9/0;
return $x;
}
function calculate("3",3,"+"){
$x = "3"+3;
return $x;
}
function calculate(2.5,3,"+"){
$x = 2.5+3;
return $x;
}
function calculate(3,3,"test"){
$x = 3 test 3;
return $x;
}
林希望有人能指出我在正确的方向。希望我没那么遥远。提前致谢。
你有x个计算函数的数量 – Eddie
闻起来像作业 –
@JakeN是的,它闻起来像一个可怕的老师。 –