1<?php
2
3class ArrayAccessible implements ArrayAccess, IteratorAggregate
4{
5    private $array;
6
7    public function __construct(array $array = [])
8    {
9        $this->array = $array;
10    }
11
12    public function offsetExists($offset)
13    {
14        return array_key_exists($offset, $this->array);
15    }
16
17    public function offsetGet($offset)
18    {
19        return $this->array[$offset];
20    }
21
22    public function offsetSet($offset, $value)
23    {
24        if (null === $offset) {
25            $this->array[] = $value;
26        } else {
27            $this->array[$offset] = $value;
28        }
29    }
30
31    public function offsetUnset($offset)
32    {
33        unset($this->array[$offset]);
34    }
35
36    public function getIterator()
37    {
38        return new ArrayIterator($this->array);
39    }
40}
41