开发者

PHP comparison confusion

// today is 03 Jan 2009
$datemonth = (int) date(开发者_Go百科"md");

if($datemonth == 0103){
    echo "Match";
} else {
    echo "Not a match";
}

I am receiving Not a match as result. Isn't 0103 equal to 103 when compared as integer? In this situation I can use if($datemonth == 103) for the intended behaviour. But why the logic is failing? A leading zero does not have any value in an integer, right?


When you begin a numeric literal with a leading zero, it means the number is in octal (base 8). You probably meant it to be a decimal (base 10) number. 0103 in octal is equal to 67 in decimal. Drop the leading zero and your code should work. See PHP documentation for more details on numeric literals.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜