How can PHP be used to dynamically assign values or IDs in table representations?

When dynamically generating tables in PHP, it can be useful to assign unique values or IDs to each row or cell. This can be achieved by using a counter variable that increments with each iteration through the data. By concatenating this counter variable with a prefix or suffix, you can create unique identifiers for each element in the table.

<?php
// Sample data for demonstration
$data = array("Apple", "Banana", "Orange");

// Initialize counter variable
$counter = 1;

// Iterate through data and generate table
echo "<table>";
foreach ($data as $item) {
    echo "<tr>";
    echo "<td id='cell_" . $counter . "'>" . $item . "</td>";
    echo "</tr>";
    $counter++;
}
echo "</table>";
?>