|
Posted by R. Rajesh Jeba Anbiah on 08/26/06 20:03
Gucci wrote:
> <?php
> /**
> * check ine year is a leap year, and return the month day array
> *
> * @param int $year **the year must bigger than zero**
> * @return array
> */
> function is_leap_year($year){
> $year=floor($year);
> if ($year<=0) {
> return false;
> }
> $flag = false;//leap year flag
>
> /*
> * check the year
> */
> if ($year%100==0) {
> if ($year%400==0) {
> $flag = true;
> }
> }
> else {
> if ($year%4==0) {
> $flag = true;
> }
> }
> $mon[0] = $flag;//leap year flag
> $mon[1] = 31;
> $mon[2] = $flag?29:28;
> $mon[3] = 31;
> $mon[4] = 30;
> $mon[5] = 31;
> $mon[6] = 30;
> $mon[7] = 31;
> $mon[8] = 31;
> $mon[9] = 30;
> $mon[10] = 31;
> $mon[11] = 30;
> $mon[12] = 31;
> return $mon;
> }
<snip>
FWIW, this is one of many reasons why everyone should read K&R.
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
Navigation:
[Reply to this message]
|