PHP treats the string 0000 as the number 0 when considering the increment. The increment operator ++ can also work with regular strings, but due to processing such as PHP it does not work, as you would expect in this case. However, if you started with a string like a0000 , then incrementing it will result in a0001 . For instance:
<?php $var = 'a0000'; for ($i = 0; $i < 100; $i++) { $var++; } echo $var;
Although, since this method of using the increment operator is a little unorthodox, I would recommend using printf("%04d", $var) (or sprtinf() ) in this case instead of the output. For instance:
<?php $var = 0; for ($i = 0; $i < 100; $i++) { printf('%04d ', $var); $var++; } ?>
source share