Skip to content
Devin Smith edited this page Feb 3, 2016 · 10 revisions

Looper provides an interface similar to Iterator with some Resource specific features.


Methods

each

Looper allows the use of $object->each(), foreach ($object), or while($object->valid() interchangeably.

foreach ($loop as $item) {
	//item
}

or

$loop->each(function() {
	// $this
});

or

while ($loop->valid()) {
	// $loop->current()
	$loop->next();
}
filter

$loop = new \Tipsy\Looper([ (object)['a' => 1], (object)['a' => 2], (object)['a' => 3] ]); $val = 0; $loop->each(function() use (&$val) { $val += $this->a; }); echo $val; // outputs 6