Reputation: 55
the output of the following code?
echo '1' . (print '2') + 3;
I tested and the result is 214, but why 214?
if I code:
echo (print '2') + 3;
the result is 24 Then, echo '1' . '24'; should be 124.
Confused...
Upvotes: 3
Views: 1034
Reputation: 1269
When the expression is parsed, the "print" statement is immediately writing its output. So there's the first 2. By definition its return value is 1.
So then the remaining expression is the character 1, followed by the numeric expression 1+3. Therefore 1 and 4.
214
Upvotes: 8