Skip to content

Instantly share code, notes, and snippets.

@thomaslarsson
Created August 11, 2012 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaslarsson/3319420 to your computer and use it in GitHub Desktop.
Save thomaslarsson/3319420 to your computer and use it in GitHub Desktop.
Return values
<?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