PHP str_pad with numbers acting strange

26 Views Asked by At

So this is strange to me. I must be missing something, but str_pad is only behaving strange with 2 numbers, 08 and 09. Every other number works just fine. I know I could use sprintf, but I'm just scratching my head on this.

I'm running Apache/2.4.23 (Win64) PHP/5.6.25

Any ideas?

<?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

There are 0 best solutions below