2
我有大量的可以说500个网址,现在使用array_unique
我可以删除任何重复的值。然而,我想要删除任何重复的值,而域保持原来的域相同(所以只有删除重复,所以这个值现在是唯一的)。PHP从数组中删除网址,如果不是唯一的
我一直在使用以下然而,这不仅能消除重复值:
$directurls = array_unique($directurls);
我一直在玩弄下获得理想的域名,但我想知道我怎么可以检查其他parse_url
域整个阵列数组中:
foreach($directurls as $url) {
$parse = parse_url($url);
print $parse['host']; //the domain name I just need to find a way to check this and remove it
}
我想我需要使用某种形式的循环也许在那里我可以得到当前主机,并检查所有其他主机在数组中。如果重复删除所有重复项并保留当前值。也许这样的事情可以工作,现在我只是测试它:
foreach($directurls as $url) {
$parse = parse_url($url);
if (in_array($parse['host'], $directurls)) {
//just looking for a way to remove while keeping unique
}
}
如果任何人有任何建议或其他途径去了解这一点,我会非常感激的建议。
让我知道是否需要多解释一下。
看array_filter() – GordonM
你怎么能告诉的网址是'原domain'?假设你有'gmail.google.com'和'plus.google.com'。 – HamZa
它不一定非常精确,但最好是去除'example.com/apage','example.com/anotherpage','example.com/yetanotherpage',这样我的数组就不会被填充100个url所有相同的域名。现在看看array_filter,谢谢。 –