Last active
December 20, 2015 02:09
-
-
Save TheDistantSea/6054423 to your computer and use it in GitHub Desktop.
Revisions
-
TheDistantSea revised this gist
Jul 22, 2013 . 1 changed file with 15 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,22 @@ class ZipIterator implements \Iterator { const ZIP_ALL = '{6087F687-D674-4549-AFBF-8D4DC07FE06F}'; private $_iterators; private $_zipAll = false; public function __construct() { foreach (func_get_args() as $argument) { if ($argument === self::ZIP_ALL) { $this->_zipAll = true; } else if (is_array($argument)) { $this->_iterators[] = new \ArrayIterator($argument); } else if ($argument instanceof \Traversable) { $this->_iterators[] = $argument; } else { throw new Exception("All arguments to ".__CLASS__." must be arrays or implement Traversable."); @@ -47,12 +54,12 @@ public function key() public function valid() { foreach ($this->_iterators as $iterator) { if ($iterator->valid() ^ !$this->_zipAll) { return $this->_zipAll; } } return !$this->_zipAll; } public function rewind() -
TheDistantSea created this gist
Jul 22, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ class ZipIterator implements \Iterator { private $_iterators; public function __construct() { foreach (func_get_args() as $traversable) { if (is_array($traversable)) { $this->_iterators[] = new \ArrayIterator($traversable); } else if ($traversable instanceof \Traversable) { $this->_iterators[] = $traversable; } else { throw new Exception("All arguments to ".__CLASS__." must be arrays or implement Traversable."); } } } public function current() { $result = []; foreach ($this->_iterators as $iterator) { $result[] = $iterator->current(); } return $result; } public function next() { foreach ($this->_iterators as $iterator) { $iterator->next(); } } public function key() { $result = []; foreach ($this->_iterators as $iterator) { $result[] = $iterator->key(); } return $result; } public function valid() { foreach ($this->_iterators as $iterator) { if ($iterator->valid()) { return true; } } return false; } public function rewind() { foreach ($this->_iterators as $iterator) { $iterator->rewind(); } } }