How can a variable in PHP be incremented to provide a sequential numbering for table rows?

To provide sequential numbering for table rows in PHP, you can use a variable that increments with each row iteration. You can initialize a variable outside of the loop and increment it within the loop to generate a unique number for each row.

<?php
// Initialize the counter variable
$counter = 1;

// Loop through your table rows
foreach ($rows as $row) {
    // Output the row with the incremented counter
    echo "<tr><td>" . $counter . "</td><td>" . $row['data'] . "</td></tr>";
    
    // Increment the counter for the next row
    $counter++;
}
?>