在php中使用一个函数

I am trying to get the return value to display but it is only doing the final else procedure. Something is wrong with my if statements... I am using an html page to call this php page... When i put in results, regardless of the operation it only displays the multiplication value

function total($num1, $num2, $op) {
    if($op == "+"){
        $total = "$num1 + $num2 = ".($num1 + $num2);
        return $total;
    } elseif($_POST['operation'] == "-"){
        $total = "$num1 - $num2 = ".($num1 - $num2);
        return $total;
    } elseif($_POST['operation'] == "/"){
        $total = "$num1 / $num2 = ".($num1 / $num2);
        return $total;
    } else{
        $total = "$num1 * $num2 = ".($num1 * $num2);
        return $total;
    }
}

echo total($num1, $num2, $op);

The problem is likely because you are mixing $op and $_POST['operation']. Also, you have a concern about your if statements. Because you return in each one, you can simplify this a great deal without increasing runtime complexity.

function total($num1, $num2, $op) {
  if($op == "+")
    return "$num1 + $num2 = ".($num1 + $num2);
  if($op == "-")
    return "$num1 - $num2 = ".($num1 - $num2);
  if($op == "/")
    return "$num1 / $num2 = ".($num1 / $num2);
  return "$num1 * $num2 = ".($num1 * $num2);
}

I think you just forgot to use $op, you used $_POST instead .

Try

function total($num1, $num2, $op)
{
  if($op == "+"){
    $total = "$num1 + $num2 = ".($num1 + $num2);
    return $total;
  }
  elseif($op == "-"){
    $total = "$num1 - $num2 = ".($num1 - $num2);
    return $total;
  }
  elseif($op == "/"){
    $total = "$num1 / $num2 = ".($num1 / $num2);
    return $total;
  }
  else{
    $total = "$num1 * $num2 = ".($num1 * $num2);
    return $total;
  }
}
echo total($num1, $num2, $op);