What are some best practices for handling duplicate values in PHP while loops?

When handling duplicate values in PHP while loops, one common approach is to use an associative array to store unique values. Before adding a value to the array, you can check if it already exists to avoid duplicates. This helps ensure that each value processed in the loop is unique.

$values = array();
while ($row = $result->fetch_assoc()) {
    $value = $row['value'];
    if (!in_array($value, $values)) {
        $values[] = $value;
        // Process the unique value here
    }
}