What are the advantages and disadvantages of using a search function that does not rely on a database in PHP?

When using a search function that does not rely on a database in PHP, the main advantage is that it can be faster and more lightweight since it does not require querying a database. However, the disadvantage is that it may not be as efficient for handling large amounts of data or complex search queries.

<?php
// Example of a search function in PHP that does not rely on a database
function searchFunction($searchTerm, $dataArray) {
    $results = array();
    
    foreach($dataArray as $data) {
        if (stripos($data, $searchTerm) !== false) {
            $results[] = $data;
        }
    }
    
    return $results;
}

// Example usage
$dataArray = ['apple', 'banana', 'orange', 'grape'];
$searchTerm = 'an';
$results = searchFunction($searchTerm, $dataArray);

print_r($results);
?>