Php counting with $i++

I have this in a loop:

<?php
    $i = 1;
    echo '<div id="'.$i.'">' . 'Anchor' . '</div>';
    echo '<a href="#'.$i.'">' . 'Link-A ' . '</a>';
    echo '<a href="#'.$i.'">' . 'Link-B ' . '</a>';
    $i++;
?>

This works fine if there is only one object. What do i have to do if i want the “$i” to count so that i get:

<div id="1">Anchor</div>
<a href="#1">Link-A </a>
<a href="#1">Link-B </a>

. . .

<div id="2">Anchor</div>
<a href="#2">Link-A </a>
<a href="#2">Link-B </a>

. . .

<div id="3">Anchor</div>
<a href="#3">Link-A </a>
<a href="#3">Link-B </a>


Source: php

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.