Working with echo or print is very easy in PHP.
At the begining it might be harder to understand concatenations or operations order, but after you master them is really easy.
But there are some cases where you wonder how does this work ?!?!
What does this print?
echo 1 . print(2+3) . 1+2;
Don’t rush to conclusions to fast.. Make sure you remember what echo and print do and what is the order of operations.
Hint 1: print also returns after the opration is done
Hint 2: echo and print are language constructs, not functions.
Click here to see the solution
You might not know that print will be executed first, but if you do, that is not enough.
So, the order of operations is:
1. evaluate 2+3 = 5
2. evaluate 1+2 = 3
3. evaluate print arguments: 5 . 3 = 53 – don’t forget, print is not a function, is a language construct as echo!
4. will actually print 53 and return true
5. evaluate echo arguments: concatenation between 1 and true = 11
6. echoes 11
So the result is: 5311