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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -