What are the advantages of splitting user input into an array of keywords for a search function in PHP?

Splitting user input into an array of keywords for a search function in PHP allows for more accurate and flexible search results. By breaking down the input into individual keywords, the search function can match against any of the keywords provided by the user, increasing the chances of finding relevant results. Additionally, it allows for the implementation of more advanced search features such as filtering by specific keywords or prioritizing certain keywords over others.

// Split user input into an array of keywords for search function
$user_input = "apple banana orange";
$keywords = explode(" ", $user_input);

// Use the keywords array in the search query
$query = "SELECT * FROM products WHERE ";
foreach ($keywords as $keyword) {
    $query .= "product_name LIKE '%$keyword%' OR ";
}
$query = rtrim($query, " OR ");

// Execute the search query
// $results = mysqli_query($conn, $query);