I have code that adds values to an array. The array is later searched in another part of my code. The values that are added to the array are not necessarily unique, so it's possible to end up with duplicate values in the array being searched. Technically speaking, even with the duplicates present in the array being searched, my code works fine and I'll be able to find the value. I just want to know if the value is in the array being searched, and don't care if it's in the array 1 time or 10,000 times.
My question is whether it's preferred (for performance and/or style reasons) to do array_unique() on my array being searched before I do the search.
So for example, suppose I want to search an array like this:
$searchMe = Array("dog", "cat", "mouse", "dog", "dog", "dog");
Note that "dog" is present 4 times. If I want to search for the value "dog", in that array, it will work fine and I will be able to tell that it's present. As mentioned above, I don't care how many times it's present, I just want to know if it's present at all.
So should I do this first before searching and then search against the de-duped array?
$searchMe_cleaned = array_unique($searchMe);
I.e., will that be faster than just searching the array with the duplicates?
Please keep in mind that although in this example the array being searched just has a few elements, the real array being searched could have hundreds or thousands of elements.
Thanks!