library collections
Gephart Collections Component
gephart/collections
Gephart Collections Component
- Monday, October 2, 2017
- by MichalKatuscak
- Repository
- 1 Watchers
- 0 Stars
- 99 Installations
- PHP
- 2 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 2 Versions
- 15 % Grown
Gephart Collections
, (*1)
Dependencies
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"