Method to determine whether a year is a leap year
How to determine whether a year is a leap year
- If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
- If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
- If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
- The year is a leap year (it has 366 days).
- The year is not a leap year (it has 365 days).
<?php function is_leap_year1( $year ) { if ((($year % 4 == 0) AND ($year % 100 != 0)) OR ($year % 400 == 0)) return true; // is leap year else return false; // not a leap year } function is_leap_year2($year) { if( $year % 400 == 0) { return true; // is leap year } else if ($year % 100 == 0) { return false; // not a leap year } else if($year % 4 == 0) { return true; // is leap year } else { return false; // not leap year } } $year = @$_GET['year'] ? $_GET['year'] : 2008; print '<pre>'; var_dump( $year ) ."\n"; var_dump( is_leap_year1($year)) ."\n"; var_dump( is_leap_year2($year)) ."\n"; ?>
No comments
Jump to comment form | comments rss [?] | trackback uri [?]