gephart / collections
Gephart Collections Component
0.5.1
2024-06-11 14:58 UTC
Requires
- php: >=7.4
- ext-json: *
Requires (Dev)
- phpmd/phpmd: @stable
- phpunit/phpunit: 9.5.21
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2024-09-12 13:44:25 UTC
README
Dependencies
- PHP >= 7.4
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"