I have an array and an external file, both contains lots of words. I want to match strings in the array with the entire external file. Then if there are identical words, I want to delete the word from the array.
Much shorten example:
$words = {"apple", "orange", "banana", "grape", "peach"}
The external text file is a pure list of words
apple
banana
melon
...
I’d like to delete the words that are in the external file, and finally get this.
$words = {"orange", "grape", "peach"}
Should I call the external file, slice every line, then save them to another array? Then compare with the source array?
What is the most effective way to compare the array and a text file?
I’d appreciate your wisdom!
You could use array_diff.(file to get an array from file.)
PS: If your external text file is very big, and you don’t want to load it to memory at one time, you could read it line by line, and check it whether it exists in the array.