PHP code example of damijanc / collection
1. Go to this page and download the library: Download damijanc/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/ */
damijanc / collection example snippets
$myCollection = new Collection;
$myCollection[] = 'value1';
$myCollection[] = 'value2';
$myCollection['data'] = 'value3';
foreach ($myCollection as $key => $item) {
//you logic here
}
class MyCoolCollection extends Collection
{
public function add(MyCoolInterface $myCoolThing)
{
$this->collectionItems[] = $myCoolThing;
return $this;
}
public function offsetGet($offset): MyCoolInterface
{
return parent::offsetGet($offset);
}
}