What are the best practices for handling search results and displaying appropriate messages in PHP scripts?

When handling search results in PHP scripts, it is important to check if the search query returned any results and display appropriate messages to the user. This can be achieved by using conditional statements to check if there are results to display, and then showing the results or a message if there are no results found.

// Assuming $searchResults is the variable containing the search results

if (count($searchResults) > 0) {
    // Display search results
    foreach ($searchResults as $result) {
        echo $result;
    }
} else {
    // Display message if no results found
    echo "No results found.";
}