PHP str_pad用数字表示奇怪

时间:2017-05-11 00:12:50

标签: php string pad

所以这对我来说很奇怪。我必须遗漏一些东西,但是str_pad只对2个数字,08和09表现得很奇怪。其他每个数字都很好。我知道我可以使用sprintf,但我只是在摸不着头脑。

我正在运行Apache / 2.4.23(Win64)PHP / 5.6.25

有什么想法吗?

<?php

// $this_month = date("m");

// if you change $this_month to 08 or 09 it breaks the code somehow...
// 01, 02, 03, 04, 05, 06, and 07 work fine.
// 8 works, 9 works, but 08 and 09 does not...

$this_month = 08;

$this_month = str_pad($this_month, 2, '0', STR_PAD_LEFT);

$last_month = $this_month - 1;
if($last_month < 1){$last_month = $last_month + 12;}
$last_month = str_pad($last_month, 2, '0', STR_PAD_LEFT);

$next_month = $this_month + 1;
if($next_month > 12){$next_month = $next_month - 12;}
$next_month = str_pad($next_month, 2, '0', STR_PAD_LEFT);

$next_next_month = $this_month + 2;
if($next_next_month > 12){$next_next_month = $next_next_month - 12;}
$next_next_month = str_pad($next_next_month, 2, '0', STR_PAD_LEFT);

$next_next_next_month = $this_month + 3;
if($next_next_next_month > 12){$next_next_next_month = $next_next_next_month - 12;}
$next_next_next_month = str_pad($next_next_next_month, 2, '0', STR_PAD_LEFT);

print "this month ".$this_month." <br/>";
print "next month ".$next_month." <br/>";
print "next next month ".$next_next_month." <br/>";

?>

0 个答案:

没有答案