I have the following code:
$value1 = 10;
$value2 = $value1 + 10; // $value2 == 20
I need the +
operator to be variable, ie in my case I need to be +
or -
.
I've tried the obvious but it sure would not work, here's the code below:
$operator = "+";
$value1 = 10;
$value2 = $value1 . $operator . 10;
Is it possible to accomplish something close to what I'm trying to do?
Important: The variable $operator
will always receive the value +
or -
in string
format.