You can re-write the expression like this to see the sequence of evaluations: ((("$x+$y=".$x) + $y)."");
Here is what happens in detail:
- The string is interpolated takes place changing
"$x+$y="
to "10+7="
- The string concatenation takes place
"10+7=".$x
leading to "10+7=10"
- The addition between a string and a number takes place
"10+7=10"+$y
evaluates to "10+7"
and eventually "17"
because php attempts to convert the string into a number. During this process it starts at the left side of the string and in your example it finds 10
. Next the +
symbol is found, which is not a number and this terminates the attempt to convert the string into a number. However, what has been found to be a number (10
) remains as the numeric interpretation of the string.
17
is concatenated with the last string
and this is echoed out.
Hope that helps,
Loddi