1

所以这对我来说很奇怪。我一定遗漏了一些东西,但是 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/>";

?>
4

0 回答 0