Can't find this anywhere, so I'll see if anyone can help me out here.
I need to remove an small array (bad emails) from a larger array (all emails). I thought that I could list the values from the small array, then find the matching keys in the large array and unset them. Almost works, but not exactly.
Here's what I've got.
<?php
$filename = "emails.txt";
$email_array = array_map('rtrim',file($filename));
$email_array = array_values(array_unique($email_array));
$filename2 = "remove_me.txt";
$remove_array = array_map('rtrim',file($filename2));
$remove_array = array_values(array_unique($remove_array));
foreach ($remove_array as $value1) {
echo "Value to remove: $value1\n";
foreach (array_keys($email_array, $value1) as $key2 => $value2) {
echo "key to remove: $key2\n";
//unset($email_array[$key2]); /* what I want to do */
}
}
$clean_array = array_values($email_array);
?>
I get a proper listing of the emails I want to remove, but when the keys are listed in the second foreach loop, they are all [0].
Close but no cigar for this novice..
Any suggestions?