Understanding str_pad() with leading zeros

后端 未结 1 1393
日久生厌
日久生厌 2020-12-12 04:20

I\'m trying to build a php function and discovered some weird behavior and I can\'t even formulate a proper question, so if anyone can explain what is going on, I would appr

相关标签:
1条回答
  • 2020-12-12 04:50

    Integer literals starting with 0 are interpreted base 8. Your second $x has the value 83. See the manual on integers for details.

    The intval() function lets you specify the base if you're reading a user string.

    If we're talking about literals, in PHP the literal 0 is decimal, while in C and C++ it is octal. It's the little differences that make life fun.

    0 讨论(0)
提交回复
热议问题