How can conditional statements be optimized in PHP to handle pagination links more efficiently?

When handling pagination links in PHP, conditional statements can be optimized by using a ternary operator to determine whether to display certain elements based on the current page number and total number of pages. This can help reduce the amount of code needed and make the logic clearer.

<?php
// Assuming $current_page and $total_pages are defined elsewhere in the code

// Display previous page link
echo ($current_page > 1) ? '<a href="?page='.($current_page - 1).'">Previous</a>' : '';

// Display page numbers
for ($i = 1; $i <= $total_pages; $i++) {
    echo ($i == $current_page) ? '<strong>'.$i.'</strong>' : '<a href="?page='.$i.'">'.$i.'</a>';
}

// Display next page link
echo ($current_page < $total_pages) ? '<a href="?page='.($current_page + 1).'">Next</a>' : '';
?>