User-Defined Function to Determine a Leap Year : Return Value « Functions « PHP






User-Defined Function to Determine a Leap Year

 
<?php

    function is_leapyear($year = 2004) {

        $is_leap = (!($year % 4) && (($year % 100) || !($year % 400)));
        return $is_leap;

    }

    $answer = is_leapyear(2000);

    if($answer) {

        echo "2000 is a leap year<BR>";

    } else {

        echo "2000 is not a leap year.<BR>";

    }

    $answer = is_leapyear(); 

    if($answer) {

        echo "2003 is a leap year.<BR>";

    } else {

        echo "2003 is not a leap year.<BR>";

    }

?>
  
  








Related examples in the same category

1.Function return more than one value
2.Math Function Library
3.A Function That Returns a Value
4.Function Requiring Two Arguments
5.A Function That Returns a Value
6.Functions that return true or false
7.Returning a value from a function
8.Returning an array from a function
9.Returning a list an array from function
10.Returning Values by Reference
11.Returning a Value by Reference
12.Returning by Reference
13.Returning More Than One Value
14.Multiple return statements in a function
15.return multiple values from a function
16.Using an array returned from a function
17.Passing Arguments and Returning Values by Reference