1

だから、これは私には奇妙です。私は何かが欠けているに違いありませんが、str_pad は 08 と 09 の 2 つの数字でのみ奇妙な動作をしています。他のすべての数字は問題なく動作します。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