How to determine if a year is a leap year using Carbon in PHP?

To determine if a year is a leap year using Carbon in PHP, you can use the isLeapYear() method provided by Carbon. Here is an example:

use Carbon\Carbon; // Create a Carbon instance for the year you want to check $year = 2022; $date = Carbon::create($year, 1, 1); // Use the isLeapYear() method to determine if it's a leap year or not $isLeapYear = $date->isLeapYear(); if ($isLeapYear) { echo "$year is a leap year."; } else { echo "$year is not a leap year."; }

In this example, we create a Carbon instance for the year 2022 and then use the isLeapYear() method to check if it's a leap year. The method returns a boolean value (true if it's a leap year and false otherwise), and we can use an if statement to display an appropriate message based on the result.