note 90149 deleted from function.pow by thiago
| From: | thiago@php.net | Date: | Wed, 08 Apr 2009 12:00:04 +0000 |
| Subject: | note 90149 deleted from function.pow by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152955@lists.php.net to get a copy of this message | ||
Note Submitter: CodeDemon
----
Here's a simple function to add leading zeros.
function leading_zeros($value, $places){
if(is_numeric($value)){
for($x = 1; $x <= $places; $x++){
$ceiling = pow(10, $x);
if($value < $ceiling){
$zeros = $places - $x;
for($y = 1; $y <= $zeros; $y++){
$leading .= "0";
}
$x = $places + 1;
}
}
$output = $leading . $value;
}
else{
$output = $value;
}
return $output;
}