php operator from variable

by Francis 2014-02-15 16:13:09

php operator from variable
We normally used in php operand and operator like
$a = 9
$b = 10
$add = $a + $b;

suppose we have user defined operators,
$operator = "+";

Here we cannot write like this,
$add = $a .$operator. $b (or) $add = eval($a .$operator. $b)

Correct way of write code is,
eval('$add = $a' .$operator. '$b;');
878
like
0
dislike
0
mail
flag

You must LOGIN to add comments