How can array_unique function in PHP be useful in removing duplicate email addresses from an array?

When dealing with an array of email addresses, it is common to have duplicates that need to be removed to ensure data integrity. The array_unique function in PHP can be useful in removing duplicate email addresses from an array by returning a new array with only unique values. This function compares values strictly, so it's important to ensure that the email addresses are in the same format before using array_unique.

// Sample array of email addresses with duplicates
$emailAddresses = ['john@example.com', 'jane@example.com', 'john@example.com', 'doe@example.com'];

// Remove duplicate email addresses
$uniqueEmails = array_unique($emailAddresses);

// Output the array with unique email addresses
print_r($uniqueEmails);