I have a string variable, $operation
, that can have values like +
or -
and two integer variables $initial
and $unit
.
So to echo the result of the arithmetic operation between them
I have to use something like
if($operation == '+') echo ($initial + $unit);
if($operation == '-') echo ($initial - $unit);
Is there a way I can do this without the IF?