-1

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?

Thank you!

BeKu
  • 5
  • 5
  • 1
    I recommend formatting the string upon output. Does this answer your question? [Zero-pad digits in string](https://stackoverflow.com/questions/324358/zero-pad-digits-in-string). – showdev Dec 12 '22 at 18:41

1 Answers1

0

You can use:

$b = $b < 10 ? "0$b" : $b;
echo $b;
Amir MB
  • 3,233
  • 2
  • 10
  • 16