How can PHP counters be effectively used to display the correct entry numbers in a loop for a guestbook?

To display the correct entry numbers in a loop for a guestbook, you can use a PHP counter variable within the loop to keep track of the entry number. Increment the counter variable on each iteration of the loop to display the correct entry number for each guestbook entry.

$counter = 1;

foreach ($guestbookEntries as $entry) {
    echo "Entry #" . $counter . ": " . $entry . "<br>";
    $counter++;
}