Reputation: 77
I would like to make a number sequential and repetitive to the beginning when it reaches the limit. For instance, the first number begins with 001, then 002, 003, and so on until it reaches 999. When it reaches 999, then the number will return to 01 and continues to repeat.
I currently have this loop:
$i = 001;
for ( $i; $i < 111; $i++)
{
echo str_pad ($i, 3, '0', STR_PAD_LEFT), '<br>';
}
But how can I make that return to the first number and continues like before? I mean if the number reaches 999, it will back to 001, 002, 003, and so on.
Upvotes: 0
Views: 103
Reputation: 408
Even if I don't quite understand why you want to do that, this is your solution :
<?php
for ($i = 001, $max = 111; $i < $max; $i++)
{
echo str_pad ($i, 3, '0', STR_PAD_LEFT), '<br>';
if ($i == $max - 1) {
$i = 001;
}
}
But this will cause an infinite loop of course.
Upvotes: 1