Created
February 25, 2012 04:57
-
-
Save raphaeldealmeida/1906547 to your computer and use it in GitHub Desktop.
Iterable
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 Iterable implements IteratorAggregate{ | |
protected $array; | |
function __construct(array $array = null ){ | |
if(is_array($array)) | |
$this->setArray($array); | |
} | |
function getArray(){ | |
return $this->array; | |
} | |
function setArray(array $array){ | |
$this->array = $array; | |
} | |
function getIterator(){ | |
return new ArrayIterator($this->array); | |
} | |
} | |
$array = array(1, 2, 3, 4); | |
$iterable = new Iterable($array); | |
foreach( $iterable as $item ){ | |
echo $item; | |
echo "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment