Have been trying to figure out this simple problem for 3 days and don't understand why the function removes only some of the values, but leaves others in place.
This is function checks a list of bad domains against a list of good domains, if it finds a bad domain, it removes it from the good domains list.
Here's my code:
// check each bad domain, against each array in good array list
$bad_domains = array('youtube.com', 'facebook.com', 'google.com', 'twitter');
$good_domains = array(
'http://www.wufoo.com/',
'https://plus.google.com/u/0/b/105790754629987588694',
'http://studioduplateau.com/ss=',
'http://twitter.com/?lang=tic-toc',
'http://twitter.com/?lang=KA-BOOM',
'http://twitter.com/?lang=tic-toc',
'http://twitter.com/?lang=KA-BOOM',
'http://twitter.com/?lang=tic-toc',
'http://twitter.com/?lang=KA-BOOM',
'http://twitter.com/?lang=tic-toc',
'http://twitter.com/?lang=KA-BOOM',
'http://twitter.com/?lang=KA-BOOM',
'lastofthemohicans.com'
);
function remove_excluded_domains($good_domains, $bad_domains) {
for($x=0; $x<count($bad_domains); $x++)
{
for($y=0; $y<count($good_domains); $y++)
{
if(strpos($good_domains[$y], $bad_domains[$x]))
{
unset($good_domains[$y]);
$good_domains = array_values($good_domains);
}
}
}
return $good_domains;
}
$spider_array = remove_excluded_domains($good_domains, $bad_domains);
For some reason it returns:
[0] => http://www.wufoo.com/
[1] => http://studioduplateau.com/ss=
[2] => http://twitter.com/?lang=KA-BOOM
[3] => http://twitter.com/?lang=KA-BOOM
[4] => http://twitter.com/?lang=KA-BOOM
[5] => http://twitter.com/?lang=KA-BOOM
[6] => lastofthemohicans.com
So it removes all http://twitter.com/?lang=tic-toc, but leaves all http://twitter.com/?lang=KA-BOOM..
Why does it do that? I tried play with array_values, but it still doesn't work.
Sorry for the silly array values, just wanted it to stand out so it's more clear. Appreciate your help.