Skip to content

Instantly share code, notes, and snippets.

@mheijkoop
Forked from josephwegner/phpEvenCheck.php
Created April 27, 2012 13:26
Show Gist options
  • Save mheijkoop/2509194 to your computer and use it in GitHub Desktop.
Save mheijkoop/2509194 to your computer and use it in GitHub Desktop.
Is Number Even
<?
// this is more the PHP-way
// requires the bcmath extension so make sure your shared hosting provider has it.
is_even($argv[1]);
function is_even($number) {
$oldnumber = $number;
goto a;
result:
if ($result) goto noteven;
goto notodd;
a:
$number = bcadd($number, "-1");
$result = !$result;
if(bccomp($number, "0") == null) goto result;
goto a;
notodd:
echo "$oldnumber is even";
goto end;
noteven:
echo "$oldnumber is odd";
end:
echo "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment