php add leading zeros code example
Example 1: prepend 0 to number php
str_pad($month, 2, '0', STR_PAD_LEFT);
Example 2: add zeros in front of number php
<?php
$num = 4;
$num_padded = sprintf("%02d", $num);
echo $num_padded; // returns 04
?>
Example 3: php format int to 9 digits with preceding zeroes
str_pad($input, 9, "0", STR_PAD_LEFT);
Example 4: php pad leading zeros
str_pad($value, 8, '0', STR_PAD_LEFT);
Example 5: format a number with leading zeros in php
sprintf('%06d', '12')