PHP code example of dashifen / collection
1. Go to this page and download the library: Download dashifen/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/ */
dashifen / collection example snippets
class MovieCollection implements AbstractCollection
{
public function current(): Movie
{
return current($this->collection);
}
public function key(): ?string
{
return key($this->collection);
}
public function valid(): bool
{
return is_string($this->key());
}
public function offsetGet ($offset): ?Movie
{
return $this->collection[$offset] ?? null;
}
public function offsetSet ($offset, $value): void
{
if (!($value instanceof Movie)) {
throw new Exception('Collection value must be a Movie');
}
$this->collection[$offset] = $value;
}
}