- var_dump: documentation ( source)
- array_values: documentation ( source)
<?php
class States implements \ArrayAccess
{
private $states = [];
/**
* @param mixed $offset
*
* @return bool
*/
public function offsetExists($offset)
{
return array_key_exists($offset, $this->states);
}
/**
* @param mixed $offset
*
* @throws UnknownStateException
*
* @return AllianceState
*/
public function offsetGet($offset)
{
if ( ! $this->offsetExists($offset)) {
throw new UnknownStateException();
}
return $this->states[$offset];
}
/**
* @param mixed $offset
* @param mixed $value
*
* @throws InvalidArgumentException
*/
public function offsetSet($offset, $value)
{
$offset = count($this->states);
$this->states[$offset] = $value;
}
/**
* @param mixed $offset
*
* @throws UnknownStateException
*/
public function offsetUnset($offset)
{
unset($this->states[$offset]);
$this->states = array_values($this->states);
}
}
$states = new States();
$states->add('foo');
$states->add('bar');
var_dump($states);