What are some potential solutions for performing a full-text search in PHP arrays?

Performing a full-text search in PHP arrays involves iterating through each element in the array and checking if the search term is present in any of the values. One solution is to use a foreach loop to iterate through the array and use strpos() function to check for the occurrence of the search term in each value.

function fullTextSearch($array, $searchTerm) {
    $results = [];
    
    foreach ($array as $key => $value) {
        if (strpos($value, $searchTerm) !== false) {
            $results[$key] = $value;
        }
    }
    
    return $results;
}

// Example usage
$array = ["apple", "banana", "cherry", "date"];
$searchTerm = "an";
$results = fullTextSearch($array, $searchTerm);

print_r($results);