How to add leading zeros to a number
Short answer
str_pad() pads a string on the left to the needed length:
<?php
echo str_pad('7', 3, '0', STR_PAD_LEFT);Output:
007With sprintf
The %05d format means "an integer five characters wide, zero-padded":
<?php
echo sprintf('%05d', 42);Output:
00042A time
Hours and minutes with zeros:
<?php
echo sprintf('%02d:%02d', 9, 5);Output:
09:05