$i = 15;
while (strlen($i) < 3)
$i = 0 . $i;
Can put it in a function or use a recursive function:
function inc_length ($num,$length) {
// $num is the number and $lenght is wanted length
if (strlen($num) >= $length)
{
return $num;
}
else
{
return inc_length (0 . $num , $length);
}
}
echo inc_length(23,5); will echo "00023"