Call us: 0031 23-75-10500  |  Language: Dutch English German
 
The PxWrappedCollection Class

PxWrappedCollection: A collection for wrapped objects

You can wrap this collection around something else (for example an array or an other collection) to ensure
that you have an object the implements the PxCollection interface.

When you loop through the collection, this object makes sure you are in fact looping over the underlying
wrapped collection.

Synopsis


Class PxWrappedCollection implements PxCollection, ArrayAccess, Countable, Traversable, IteratorAggregate

Properties

Methods

public PxWrappedCollection::__construct ( mixed $collection , [callable $callback = NULL] )
public integer PxWrappedCollection::count ( void )
public boolean PxWrappedCollection::offsetExists ( integer $index )
public mixed PxWrappedCollection::offsetGet ( integer $index )
public PxWrappedCollection::offsetSet ( integer $index , mixed $value )
public PxWrappedCollection::offsetUnset ( integer $index )
public array PxWrappedCollection::toArray ( void )
protected mixed PxWrappedCollection::wrap ( mixed $object )

Examples


Example
How to use the PxWrappedCollection
// Return the number of fibonacci
function fibonacci($integer)
{
    if ($integer == 1 || $integer == 2) return 1;
    return fibonacci($integer - 1) + fibonacci($integer - 2);
}

// create the PxWrappedCollection with the integers and the fibonacci callback
$collection = new PxWrappedCollection(array(1,3,6,9,12), 'fibonacci');

// display the fibonacci numbers of the collection
foreach ($collection as $f) var_dump($f);
int(1)
int(2)
int(8)
int(34)
int(144)