Skip to content

Instantly share code, notes, and snippets.

@ShinNoNoir
Created April 27, 2012 12:11
Show Gist options
  • Save ShinNoNoir/2508693 to your computer and use it in GitHub Desktop.
Save ShinNoNoir/2508693 to your computer and use it in GitHub Desktop.
Checking whether a number is even or odd: the PHP way! :p
function iseven($n) {
$lastdigit = substr($n, -1);
if ($lastdigit == '0')
return true;
elseif ($lastdigit == '2')
return true;
elseif ($lastdigit == '4')
return true;
elseif ($lastdigit == '6')
return true;
elseif ($lastdigit == '8')
return true;
else
return isodd($n) != true;
}
function isodd($n) {
$lastdigit = substr($n, -1);
if ($lastdigit == '1')
return true;
elseif ($lastdigit == '3')
return true;
elseif ($lastdigit == '5')
return true;
elseif ($lastdigit == '7')
return true;
elseif ($lastdigit == '9')
return true;
else
return iseven($n) != true;
}
@CrossfireCurt
Copy link

You are retarded.

@ShinNoNoir
Copy link
Author

I have an additional pair of sarcasm goggles for sale. Interested? :p

@CrossfireCurt
Copy link

CrossfireCurt commented Apr 27, 2012 via email

@ShinNoNoir
Copy link
Author

Well, on the other hand I can't blame you. When it comes to PHP, you're never sure whether someone's serious or not. :)

@CrossfireCurt
Copy link

CrossfireCurt commented Apr 27, 2012 via email

@CrossfireCurt
Copy link

CrossfireCurt commented Apr 27, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment