Home > Backend Development > PHP Tutorial > 为什么我写的这程序的$a+$b和$a-$b不能计算,别的能计算啊,求大神解决!!!

为什么我写的这程序的$a+$b和$a-$b不能计算,别的能计算啊,求大神解决!!!

WBOY
Release: 2016-06-23 14:12:01
Original
1028 people have browsed it

函数 类

    $a=$_REQUEST["num1"];
$b=$_REQUEST["num2"];
$fuhao=$_REQUEST["fuhao"];

    class Cat{
    public function jisuan($a,$b,$fuhao){

switch($fuhao){
    case"+":
$a+$b;
    echo '$a+$b='.$a+$b;
break;
case"-":
$a-$b;
    echo '$a-$b='.$a-$b;
break;
case"*":
$a*$b;
    echo '$a*$b='.$a*$b;
break;
case"/":
$a/$b;
    echo '$a/$b='.$a/$b;
break;
}
}     
}

$cat1=new cat();
    $cat1->jisuan ($a,$b,$fuhao);

?>

回复讨论(解决方案)

运行正常,可以计算啊

额。。。题目没看清楚,应该是优先级的问题,你把    case"+":
$a+$b;
    echo '$a+$b='.($a+$b);
break;
case"-":
$a-$b;
    echo '$a-$b='.($a-$b);
break;
改成  case"+":
$a+$b;
    echo '$a+$b='.$a+$b;
break;
case"-":
$a-$b;
    echo '$a-$b='.$a-$b;
break;

养成加括弧的习惯

echo '$a-$b=' . ($a-$b);echo '$a-$b=' , $a-$b;
Copy after login

$c = $a+$b;echo '$a+$b='.$c;
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template