Просмотр поста

.
L!MP

Как то так, не?

class CustomArray implements ArrayAccess
{
    protected $data = [];
    
    public function __construct(array $data)
    {
        $this->data = $data;
    }
    
    public function offsetSet($offset, $value)
    {
        if (is_null($offset)) {
            $this->data[] = $value;
        } else {
            $this->data[$offset] = $value;
        }
    }
    
    public function offsetExists($offset)
    {
        return isset($this->data[$offset]);
    }

    public function offsetUnset($offset)
    {
        unset($this->data[$offset]);
    }
    
    public function offsetGet($offset)
    {
        return isset($this->data[$offset]) ? $this->data[$offset] : 0;
    }
}

$m = new CustomArray(['alfa' => 123, 'beta' => 234]);

var_dump($m['alfa']);  //=> 123
var_dump($m['beta']);  //=> 234
var_dump($m['gamma']); //=> 0

$m['gamma'] = 345;

var_dump($m['gamma']); //=> 345