I am making very simple program in PHP . Tryig to addition first ..
But dont know ..
Here is code
<?php
$a=12;
$b=10;
$c="+";
$res=$a."$c".$b;
echo $res;
?>
it output 12+10 as it is concecate..
$c is anything.
Any idea how to do this
$c is now a string and not a expression "+" is not equal to +.
So:
$res=$a + $b;
If you would really need your structure you would have to do something evil like using eval() or you could do:
$a=12;
$b=10;
$operator='+';
switch($operator) {
case '+':
$res=$a + $b;
break;
case '-':
$res=$a - $b;
break;
}
$cinto quotes like"$c"? Also why do you put the operator into a variable? If you just write it without the string, it should work.