1. Go to this page and download the library: Download digitick/collection 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/ */
e class you want to be in your list collection
class MyItem {
public $value;
/**
* MyItem constructor.
* @param $value
*/
public function __construct($value)
{
$this->value = $value;
}
/**
* @return mixed
*/
public function getValue()
{
return $this->value;
}
/**
* @param mixed $value
* @return MyItem
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
}
// Declare your list collection for class MyItem
class MyItemList extends \Digitick\Foundation\Collection\AbstractTypedList
{
/**
* @var string
*/
protected static $CLASSORTYPENAME = "MyItem"; // Ensure that the list will only contains items of class MyItem
}
// You must give the size of your list
$myList = new MyItemList (3);
// You can access to your list like standard PHP array
$myList [0] = new MyItem(1);
$myList [1] = new MyItem(2);
$myList [2] = new MyItem(3);
// Except for this syntax : new values can not be pushed at the end of the list;
//$myList [] = new MyItem(3); // Throw exception
// You can iterate over your list with foreach syntax
/** @var MyItem $item */
foreach ($myList as $item) {
echo "Item : " . $item->getValue() . "\n";
}