for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace phootwork\collection;
use \Iterator;
/**
* Represents a Set
*
* @author Thomas Gossmann
*/
class Set extends AbstractList {
* Creates a new Set
* @param array|Iterator $collection
public function __construct($collection = []) {
$this->addAll($collection);
}
* Adds an element to that set
* @param mixed $element
* @return $this
public function add($element) {
if (!in_array($element, $this->collection, true)) {
$this->collection[$this->size()] = $element;
return $this;
* Adds all elements to the set
public function addAll($collection) {
foreach ($collection as $element) {
$this->add($element);
* Removes an element from the set
public function remove($element) {
$index = array_search($element, $this->collection, true);
if ($index !== null) {
unset($this->collection[$index]);
* Removes all elements from the set
public function removeAll($collection) {
$this->remove($element);