PHP code example of gephart / collections
1. Go to this page and download the library: Download gephart/collections library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gephart / collections example snippets
$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"];
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"