0

I'm trying to make a for loop with numbers given by user ($start and $limit), but I want to be able to write '0001' as $start and '1000' as $limit and print each one of numbers. The problem is, only the first number is printed as '000..' and after increment, those zeros disappear. This is my code:

 $start = 0001;
 $limit = 1000;

 for ($i=$start; $i <= $limit; $i++) {
   echo $i.'<br>';
 }

outputs:

001
2
3
...
1000

Is there any way to make it as:

0001
0002
...
1000
Ank
  • 1,864
  • 4
  • 31
  • 51

1 Answers1

0

Try

  $start = 1;
  $limit = 1000;

   for ($i=$start; $i <= $limit; $i++) {
      printf("%04d<br>",$i);
   }
Carsten Massmann
  • 26,510
  • 2
  • 22
  • 43