gephart/collections

Gephart Collections Component

0.5 2017-10-02 16:23 UTC

This package is not auto-updated.

Last update: 2024-02-18 01:02:45 UTC


README

Build Status

Dependencies

  • PHP >= 7.1

Instalation

composer require gephart/collections dev-master

Using

Collection without a specific type

$collection = new Gephart\Collections\Collection();

$collection->add("Something"); // Index - 0
$collection->add(123); // Index - 1

$item = $collection->get(1); // 123

$collection->remove(1); // Delete item with index 1

$items = $collection->all(); // [0 => "Something"];

Collection with a specific type

class SpecificEntity { public $text = ""; }

$item1 = new SpecificEntity();
$item1->text = "first";

$item2 = new SpecificEntity();
$item2->text = "second";

$collection = new Gephart\Collections\Collection(SpecificEntity::class);

$collection->add($item1);
$collection->add($item2);
// Or use method collect(): $collection->collect([$item1, $item2]);

$item = $collection->get(1);
echo $item->text; // "second"