For what you want to do, I recommend using for
.
Example:
<?php for ($i = 1; $i <= $abas; $i++): ?>
<li><?= $i ?></li>
<?php endfor ?>
for
is a Repetition Structure, which, as the name suggests, is intended to execute a number of repetitions while the condition of the second parameter is met.
It is divided into three parts:
- the beginning. In case
$i = 1
is the initial setting value.
- the condition for the replay to continue running. In this case, while
$i
is less than or equal to $abas
.
- What to do after incrementing. In this case,
$i++
increments +1
in $i
to the next loop.
The <?= $i ?>
excerpt will print the current value of $i
in HTML.
In versions prior to PHP's 5.4, you would have to use <?php echo $i; ?>
.