Zero fill a number using PHP
Have you ever needed to make sure your number is a certain length for output? Say you have the number 6 but need to make sure it is 4 digits and out put like: 0006. How would you go about this? One way to do this is the following:
<?php
function zerofill ($num,$zerofill) {
while (strlen($num)<$zerofill) {
$num = "0".$num;
}
return $num;
}
?>
The usage of this code would be:
<?php echo zerofill(6, 7); ?>
Output will be 00006
Keep Enjoying..


August 2nd, 2009 at 7:54 PM
Gud stuff… i am expecting more from u… keep posting