Skip to content

Instantly share code, notes, and snippets.

@raphaeldealmeida
Created February 25, 2012 04:57
Show Gist options
  • Save raphaeldealmeida/1906547 to your computer and use it in GitHub Desktop.
Save raphaeldealmeida/1906547 to your computer and use it in GitHub Desktop.
Iterable
<?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