Why does "/" . date("Y") + 1 in PHP return 1?
Why does
"/" . date("Y") + 1
in PHP return 1
?
And a similar question开发者_开发问答, why does date("Y") . "/" . date("Y") + 1
return 2011
?
I am quessing it has something to do with operator precedence, because date("Y") . "/" . (date("Y") + 1)
does return the expected "2010/2011"
Yep. .
binds more tightly than +
, so:
"/" . date("Y") + 1
is parsed as:
("/" . date("Y")) + 1
The left side doesn't start with any numbers, so when you convert it to a number, it becomes 0. Same with the latter:
(date("Y") . "/" . date("Y")) + 1
The left side of the +
starts with 2010 then some non-digits, so when it gets converted to a number, it becomes 2010. Then you add 1.
when you use point . thats mean that a string and after that your try to + this string whith a integer , that not logical
精彩评论