Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

41 lines (26 sloc) 0.93 kb

Array collection

Provides api to query items from array


Example


require("./array.php");

$collection = new ArrayCollection();
$collection->add((object) array("name" => "Vova", "age" => 16));
$collection->add((object) array("name" => "Dima", "age" => 18));
$collection->add((object) array("name" => "Vika", "age" => 23));
$collection->add((object) array("name" => "Vova", "age" => 17));
$collection->add((object) array("name" => "Vova", "age" => 16));



var_dump($collection->data());

# select all items with name "Vova"
# ArrayCollection is returned
$allVovas = $collection->where(array("name" => "Vova")); 

var_dump($allVovas);

# removing from collection all "Vova" items
$collection->remove($allVovas);

var_dump($collection->data());

# get first item
var_dump($collection->first());

# get first item by pattern
var_dump($collection->first(array("age" => 23)));
Jump to Line
Something went wrong with that request. Please try again.