How can the code for the PHP calendar be optimized for better performance and readability?

To optimize the code for the PHP calendar, we can improve performance by reducing unnecessary loops and conditionals, using built-in PHP functions for date manipulation, and organizing the code for better readability by breaking it down into smaller, more manageable functions.

<?php
function generate_calendar($month, $year) {
    $first_day = strtotime("first day of $year-$month");
    $last_day = strtotime("last day of $year-$month");
    
    // Generate calendar HTML here
}

// Example usage
generate_calendar(8, 2023);
?>