What best practices can be followed to avoid duplicate rows in PHP-generated tables?

To avoid duplicate rows in PHP-generated tables, one best practice is to use an array to store unique values and check against this array before adding a new row to the table. This way, you can ensure that only unique rows are displayed in the table.

<?php
$uniqueValues = array();

// Loop through your data and generate table rows
foreach ($data as $row) {
    // Check if the value is already in the uniqueValues array
    if (!in_array($row['value'], $uniqueValues)) {
        // Add the value to the uniqueValues array
        $uniqueValues[] = $row['value'];
        
        // Generate the table row
        echo "<tr><td>{$row['value']}</td></tr>";
    }
}
?>