Snippets > PHP Leading Zeros


#php

Add a leading zero to numbers with less than 2 digits.

$number = 3;
echo sprintf('%02d', $number);

This will output:

03