Created
April 27, 2012 12:11
-
-
Save ShinNoNoir/2508693 to your computer and use it in GitHub Desktop.
Checking whether a number is even or odd: the PHP way! :p
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
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; | |
} |
Hahaha okay point taken. I am the retard. :(
…Sent from my iPhone
On Apr 27, 2012, at 9:45 AM, Raynor ***@***.*** wrote:
I have an additional pair of sarcasm goggles for sale. Interested? :p
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2508693
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. :)
ha, yes this is true. It's unfortunate how many serious gists (and PHP in
general) there are with the outrageously low quality of code you pointed
out.
…On Fri, Apr 27, 2012 at 9:56 AM, Raynor Vliegendhart < ***@***.*** > wrote:
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. :)
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2508693
THAT IS SO FRIENDLY OF YOU
…On Fri, Apr 27, 2012 at 10:00 AM, Brandon < ***@***.*** > wrote:
Curt's right.
Here, I'm feeling friendly today:
function is_even($int)
{
if (!is_int($int)) throw new Exception("not an int");
return ($int%2==0);
}
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2508693
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have an additional pair of sarcasm goggles for sale. Interested? :p