Created
August 11, 2012 00:39
-
-
Save thomaslarsson/3319420 to your computer and use it in GitHub Desktop.
Return values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = array | |
( | |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, | |
"String 1", "Hello", 'World' | |
); | |
foreach ( $array as $value ) | |
{ | |
// Get result | |
$result = $this->is_even_integer($value); | |
// Result is true | |
if ( $result ) | |
{ | |
echo "The number '{$value}' is even <br />"; | |
} | |
// Result is false | |
if ( $result === false ) { | |
echo "The number '{$value}' is odd <br />"; | |
} | |
// Result is null | |
if ( $result === null ) | |
{ | |
echo "'{$value}' is not an integer <br />"; | |
} | |
} | |
function is_even_integer( $number ) | |
{ | |
// Return null if not an integer | |
if ( ! is_integer($number)) | |
{ | |
return null; | |
} | |
// Check if value is odd or even | |
return ( $number % 2 === 0 ) ? true : false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment