A simple question with summation variables in PHP?

Like a simple situation, but did not understand. How to sum +1 to the number 0001? I have in the summation we get the number 2, and should be 0002. How to solve?
March 19th 20 at 09:04
5 answers
March 19th 20 at 09:06
Solution
echo str_pad("2", 4, "0", STR_PAD_RIGHT);
March 19th 20 at 09:08
At first, work with numbers as numbers — summarize as you need — and if output — format as you want
March 19th 20 at 09:10
there is no such number as 0001, to output a similar result can be to use sprintf
March 19th 20 at 09:12
And correctly. You need to go to 1 class to learn, something to find out what number 0001 does not exist. Then, when we finish school, you can read information about data types and to learn what integers, what is the row.
The php interpreter translates line number to 0001 and the result is an integer 1, then adds a value of 2 turns
March 19th 20 at 09:14
<?php

for ($i = 0; $i < 15; $i++) {
 echo sprintf("%04d", $i).PHP_EOL;
}


Out:
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014

Find more questions by tags PHP