Answered by : the-strangest-salamander
$number = 4;
str_pad($number, 2, '0', STR_PAD_LEFT); // returns 04
$number = 14;
str_pad($number, 2, '0', STR_PAD_LEFT); // returns 14
Source : https://stackoverflow.com/questions/5659042/php-prepend-leading-zero-before-single-digit-number-on-the-fly | Last Update : Tue, 22 Dec 20
Answered by : enchanting-emu-txqk00udksy4
str_pad($month, 2, '0', STR_PAD_LEFT);
Source : https://stackoverflow.com/questions/5659042/php-prepend-leading-zero-before-single-digit-number-on-the-fly/5659093 | Last Update : Tue, 07 Jul 20
Answered by : itchy-iguana-hxd9gtwnchg0
$number = 4;
echo(str_pad($number, 2, '0', STR_PAD_LEFT)); // returns 04
$number = 14;
echo(str_pad($number, 2, '0', STR_PAD_LEFT)); // returns 14
Source : | Last Update : Wed, 09 Feb 22
Answered by : lovely-llama-lpft77abt2tl
<?php
$num = 4;
$num_padded = sprintf("%02d", $num);
echo $num_padded; // returns 04
?>
Source : https://stackoverflow.com/questions/5659042/php-prepend-leading-zero-before-single-digit-number-on-the-fly | Last Update : Sat, 02 May 20
Answered by : tushar-saha
sprintf('%06d', '12')
Source : https://stackoverflow.com/questions/1699958/formatting-a-number-with-leading-zeros-in-php | Last Update : Wed, 10 Mar 21