简单数学的函数不起作用,我做错了什么?

时间:2018-03-09 作者:Jenny

这是我在索引文件中写的

<?php
echo "Please enter your first number?\\n";

$first = stream_get_line(STDIN, 100, "\\n");

echo "Please enter /, +, * or /?\\n";

$operator = stream_get_line(STDIN, 100, "\\n");

echo "Please enter your second number?\\n";

$second = stream_get_line(STDIN, 100, "\\n");

include_once "library/maths/mathsA.php";

echo doMathsA ($first, $operator, $second); 
功能doMathsA 看起来像

<?php
function doMathsA ($first, $operator, $second){

  switch ($operator)

    {
        case \'+\';
            $result=$first+$second;
           break;

        case \'*\';
            $result=$first*$second;
            break;

        case \'/\';
            $result=$first/$second;
            break;

        case \'-\';
            $result=$first-$second;
             break;  
}}

echo "Your result is $result"; 

1 个回复
SO网友:Peter HvD

switch/case的正确语法是使用冒号: 不是分号; 在case之后,所以。。。

case \'+\' :
    $result=$first+$second;
    break;
等等,

结束