Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

php zero + number with leading zero as output if needed

When I do this..

$a = "00";
$b = $a+6;

echo $b;

Output is 6, but I need output 06 "with leading zero".
The leading zero I need if the + number ist between 1-9.
I don’t figured out how I can do this, I’ve tried everything possible, the output is always
3 or 6 or 8 without zero.

How I can do this? where is the trick?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you!

>Solution :

You can use:

$b = $b < 10 ? "0$b" : $b;
echo $b;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading