即時通訊對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是的,它聞起來像一個可怕的老師。 –