How can one ensure that a search in PHP only returns exact matches and not partial matches like in the example provided?
To ensure that a search in PHP only returns exact matches and not partial matches, you can use the strict comparison operator (===) to compare the search term with the elements in the array. This will ensure that only exact matches are returned.
$searchTerm = "apple";
$fruits = ["apple", "banana", "cherry", "pineapple"];
$exactMatches = array_filter($fruits, function($fruit) use ($searchTerm) {
return $fruit === $searchTerm;
});
print_r($exactMatches);