Created
March 6, 2013 00:54
-
-
Save amcgowanca/5095828 to your computer and use it in GitHub Desktop.
Fanshawe College, INFO-5094: LAMP 2, Project 1 - IteratorMode examples of using Bitwise operators
This file contains hidden or 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 | |
class IteratorMode | |
{ | |
const KEEP = 1; | |
const DELETE = 2; | |
const FIFO = 4; | |
const LIFO = 8; | |
public static function isKeep($mode) | |
{ | |
return 1 == ($mode & self::KEEP); | |
} | |
public static function isFifo($mode) | |
{ | |
return 4 == ($mode & self::FIFO); | |
} | |
} | |
// Example usage ... | |
$keep_and_fifo = IteratorMode::KEEP | IteratorMode::FIFO; | |
if (IteratorMode::isKeep($keep_and_fifo)) { | |
// Yay! Our iterator will not delete nodes as we traverse. | |
} | |
$xored_keep_and_fifo = IteratorMode::DELETE ^ IteratorMode::FIFO; | |
if (IteratorMode::isFifo($xored_keep_and_fifo)) { | |
// Awesome! We are moving forward, first-in, first-out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: The
IteratorMode::DELETE ^ IteratorMode::FIFO
could also be an OR instead of XOR.