I have code that adds values to an array. The array will later search in another part of my code. The values that are added to the array are not necessarily unique, so duplicate values can be found as a result of the search. From a technical point of view, even if there are duplicates present in the array, my code works fine and I can find the value. I just want to know if the value is in the array that is being searched and does not care if it is in the array 1 time or 10,000 times.
My question is whether he prefers (for performance and / or style) to execute array_unique () in my array, which is searched before doing the search.
So, for example, suppose I want to search for such an array:
$searchMe = Array("dog", "cat", "mouse", "dog", "dog", "dog");
Please note that the “dog” is present 4 times. If I want to find the value "dog", in this array it will work fine, and I can say that it is present. As mentioned above, I don’t care how many times he is present, I just want to know if he is present at all.
So, should I do this first before searching and then doing a search on a nullified array?
$searchMe_cleaned = array_unique($searchMe);
Ie, will it be faster than just finding an array with duplicates?
, , , .
!