如何在 PHP 公共函数中返回 sqrt 结果

问题描述

我有一个基于 switch case 的计算器,我想返回 0 到 9 之间数字的平方根结果。其他所有函数都在工作,只是我不知道如何输出的 sqrt 函数

<?PHP
class Calculatrice{
public function calcul($entry = "2+3")
{
   return $this->calculate($entry);
}

private function calculate($data){
    $data_array = str_split($data);
    return $this->operation($data_array);
}
public function operation($array){
    switch ($array[1]) {
        case "+":
            return $this->addition($array[0],$array[2]);
            break;
        case "-":
            return $this->soustraction($array[0],$array[2]);
            break;
        case "*":
            return $this->multiplication($array[0],$array[2]);
            break;
        case "/":
            return $this->division($array[0],$array[2]);
            break;
        case "%":
            return $this->modulo($array[0],$array[2]);
            break;
        case "√":
            return $this->racine($array[0]);
            break;
        default:
            break;
    }
}

public function addition($left,$right){
   return (int)$left + (int)$right;
}
public function soustraction($left,$right){
    return (int)$left - (int)$right;
 }
 public function multiplication($left,$right){
    return (int)$left * (int)$right;
 }
 public function division($left,$right){
    return (float)$left / (float)$right;
 }
 public function modulo($left,$right){
    return (int)$left % (int)$right;
 }
 public function racine($left,$right){
    return (int)sqrt($left);
 }
 }
 ?>

我认为这只是关于显示 return 语句。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)