Store plus and minus in a variable PHP -
how can solve problem:
if ($variable == 1) { $math = "-"; } else { $math = "+"; } $numberone = 10; $numbertwo = 10; $result = $numberone $math $numbertwo;
this doesn´t work, there way solve this?
this work example. subtraction same adding negative. far safer alternative of using eval.
if ($variable == 1) { $modifier = -1; } else { $modifier = 1; } $numberone = 10; $numbertwo = 10; $result = $numberone + ($numbertwo * $modifier);
Comments
Post a Comment