In the expression echo "Você nasceu em ". date('Y') - 20
, you are subtracting the concatenation of the string with the date.
For you to understand better, it would be the same as for you to do this:
echo "Você nasceu em 2017" - 20;
So it's important to use parentheses. For in such cases, the expression is first processed inside the parentheses and then concatenated.
Tip : In cases like this, I usually use the sprintf
function to better format the string:
echo sprintf("Você nasceu em %d", date('Y') - 20);
See a test at IDEONE
Depending on the version of PHP you are using (I believe from version 7), you might get an error if you do an operation like that mentioned in the question:
A non-numeric value encountered