What are the best practices for handling and displaying large amounts of search results in PHP?

When handling and displaying large amounts of search results in PHP, it's important to paginate the results to improve performance and user experience. Pagination allows you to split the results into manageable chunks, reducing the load on the server and making it easier for users to navigate through the data.

// Assuming $searchResults is an array containing all the search results
$resultsPerPage = 10;
$totalResults = count($searchResults);
$totalPages = ceil($totalResults / $resultsPerPage);

$page = isset($_GET['page']) ? $_GET['page'] : 1;
$start = ($page - 1) * $resultsPerPage;
$end = $start + $resultsPerPage;

$paginatedResults = array_slice($searchResults, $start, $resultsPerPage);

foreach ($paginatedResults as $result) {
    // Display the search result
}

// Display pagination links
for ($i = 1; $i <= $totalPages; $i++) {
    echo "<a href='?page=$i'>$i</a> ";
}