how can I do this?
$v1=105;
$v2=90;
if ($value=='subtraction'){
$operator='-';
}else{
$operator='+';
}
$new_value=$v1.$operator.$v2;
So it should return 105-90=15 or 105+90=195. But how can I use the $operator variable as a operator? For example this doesn’t work:
eval("$new_value=$v1".$operator."$v2");
Thanks for the help!
I suggest not doing this, but to use
eval, you’d have to do it like this:I suggest doing it something like this instead (ie: Don’t use a variable for operator, just do the calculation):