What is the significance of using DISTINCT in a MySQL query when retrieving data for an array in PHP?

When retrieving data for an array in PHP from a MySQL database, using DISTINCT in the query ensures that only unique values are returned. This can be useful when you want to avoid duplicate entries in your array, especially when dealing with large datasets. By using DISTINCT, you can streamline your array and make it more efficient for processing.

$query = "SELECT DISTINCT column_name FROM table_name";
$result = mysqli_query($connection, $query);

$data = array();
while ($row = mysqli_fetch_assoc($result)) {
    $data[] = $row['column_name'];
}

print_r($data);