Just use the function sprintf(). You can pass a format-string and the number you would like to output to this function.
Here is a small example:
$x = 7;
$y = 13;
sprintf("%03d", $x); // 007
sprintf("%03d", $y); // 013
sprintf("%02d", $x); // 07
sprintf("%02d %02d", $x, $y); // 07 13
The "d" in the format-string is standing for an integer number, the "03" is caring about filling 3 places.
The two last lines are showing examples of how to use this function to fill 2 places and to output more than one numbers at once.
Another function that could be interesting for you is str_pad() - this function is working with strings instead of numbers.
we can use it like it is shown in the following example:
$str = 'abc';
echo str_pad($str, 5, '.'); // '..abc'
echo str_pad($str, 5, '.', STR_PAD_RIGHT); // '..abc'
echo str_pad($str, 5, '.', STR_PAD_LEFT); // 'abc..'
echo str_pad($str, 5, '.', STR_PAD_BOTH); // '.abc.'
echo str_pad($str, 8, '. '); // '. . .abc'
echo str_pad($str, 8); // ' abc'
The function takes a string as the first parameter and the second parameter is a value, how long the string should be.
The third, optional parameter is the character or the set of characters to be used for filling. If you omit this parameter, a blank is used. If the number of characters for filling is not fitting, the filling characters are just cut, so that they come to the right length.
The fourth and last parameter specifies whether the string should be filled right justified (STR_PAD_RIGHT), left justified (STR_PAD_LEFT) or centrally (STR_PAD_BOTH). If you omit this parameter, the function uses a right alignment.