When the echo statement contains strings, string operators, variables, and arithmetic operators, why can't you perform arithmetic operations instead of directly outputting the last variables and strings?

$a=10;
$b=60;
echo "$a*$b=".$a*$b."<br>";  //$a*$b=600<br>
echo "$a/$b=".$a/$b."<br>";  //$a/$b=0.16666666666667<br>
echo "$a+$b=".$a+$b."<br>";  //60<br>
echo "$a-$b=".$b+$a."<br>";  //10<br>

can output the last variable and string without reporting an error. What is the reason for this?

Php
Mar.11,2021

Note the difference between''and "'.
''does not parse variables,"parse variables
echo' $apropriated variables.
'
'in
'$apropriated variables' this is a string, so let's output

as a string.

there will be a waring error in the last two outputs, indicating that A non-numeric value encountered said $a + has a problem


because the operator precedence is different
* /% is higher than . , so first calculate * /%
+ -. sibling, so operate from left to right

Menu