Last active
December 17, 2015 11:11
-
-
Save jserrao/f892d18872c8f3d013b3 to your computer and use it in GitHub Desktop.
PHP modulus in action
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 | |
// % is modulus; it takes $object, divides by 5 and looks at the remainder | |
// It's a good way to find the nth item in an array for PHP | |
$object = 20; | |
// Case 1 | |
// in this case 20/5 = 4.0, making the remainder 0, satisfying the if case | |
// result: $boo = true | |
if ($object % 5 == 0) { | |
$boo = true; | |
} else { | |
$boo = false; | |
} | |
// Case 2 | |
// in this case 20/8 = 2.5, making the remainder 0 and not satisfying the if case | |
// result: $boo = false | |
if($object % 8 == 0) { | |
$boo = true; | |
} else { | |
$boo = false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment