0
Hello.
I want to return the result of an operation using two numbers and the operator as parameter. It turns out that my result is a string.
<?php
$n1 = $_POST['n1']; //primeiro número
$n2 = $_POST['n2']; //segundo número
$operador = $_POST['operador']; // +-*/
$resultado = fazConta($n1,$n2,$operador);
echo $resultado;
function fazConta($n1,$n2,$operador){
$x = $n1.$operador.$n2;
return $x;
}
?>
In the above example, it returns the operation and not the result. Example: "3+2" and not "5".
RelatedCalculator in php. Can you do the
eval()
ex:$op = '+';
eval("echo 30 $op 5;");
but of a read before in Eval is either good or bad?– rray
Nor would I be able to return
5
, for the.
is the string concatenation operator.– Bacco