I want to format my array vars to that numbers under ten have leading zeros, so:
$myArray=array(1,2,3,10,11,100);
So that it is:
$myArray=array(01,02,03,10,11,100);
Is there an easy function for this?
Thanks in advance.
In php, a leading zero means the number is a octal number.
You should just format it at the output time like:
$myArray=array(1,2,3,10,11,100);
foreach ($myArray as $var) {
echo sprintf("%02d\n", $var);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With