FOF30\Utils\Collection::toArray PHP Method

toArray() public method

Get the collection of items as a plain array.
public toArray ( ) : array
return array
    public function toArray()
    {
        return array_map(function ($value) {
            return is_object($value) && method_exists($value, 'toArray') ? $value->toArray() : $value;
        }, $this->items);
    }

Usage Example

Example #1
0
 public function testToArrayCallsToArrayOnEachItemInCollection()
 {
     $item1 = $this->getMock('FOF30\\Registry\\Registry', array('toArray'));
     $item1->expects($this->once())->method('toArray')->will($this->returnValue('foo.array'));
     $item2 = $this->getMock('FOF30\\Registry\\Registry', array('toArray'));
     $item2->expects($this->once())->method('toArray')->will($this->returnValue('bar.array'));
     $c = new Collection(array($item1, $item2));
     $results = $c->toArray();
     $this->assertEquals(array('foo.array', 'bar.array'), $results);
 }