How can a PHP script be structured to reset and display birthdays from the beginning of the year if no more birthdays are left in the current year?

To reset and display birthdays from the beginning of the year if no more birthdays are left in the current year, you can create a function that checks if there are any remaining birthdays in the current year. If there are no more birthdays, the function can reset the list of birthdays to the beginning of the year and display them accordingly.

<?php
function displayBirthdays($birthdays) {
    $currentDate = date("Y-m-d");
    $currentYear = date("Y");

    $upcomingBirthdays = array_filter($birthdays, function($birthday) use ($currentDate, $currentYear) {
        return date("Y", strtotime($birthday)) == $currentYear && $birthday >= $currentDate;
    });

    if (empty($upcomingBirthdays)) {
        $birthdays = array_filter($birthdays, function($birthday) use ($currentYear) {
            return date("Y", strtotime($birthday)) == $currentYear;
        });
    }

    foreach ($birthdays as $birthday) {
        echo $birthday . "<br>";
    }
}

$birthdays = ["2022-01-15", "2022-03-20", "2022-06-10", "2022-09-25"];
displayBirthdays($birthdays);
?>