What is the purpose of using array_unique in PHP and how does it help in filtering duplicate URLs?
When dealing with arrays in PHP, it is common to encounter duplicate values that need to be removed. The array_unique function in PHP helps in filtering out duplicate values from an array, ensuring that each value appears only once. When dealing with URLs, array_unique can be used to remove duplicate URLs from an array, ensuring that each URL is unique.
// Sample array with duplicate URLs
$urls = array("https://example.com", "https://example.com", "https://google.com", "https://google.com");
// Remove duplicate URLs using array_unique
$unique_urls = array_unique($urls);
// Output unique URLs
print_r($unique_urls);