Skip to content

Instantly share code, notes, and snippets.

@gabrieljmj
Last active August 29, 2015 14:14
Show Gist options
  • Save gabrieljmj/cb0783b9071090644614 to your computer and use it in GitHub Desktop.
Save gabrieljmj/cb0783b9071090644614 to your computer and use it in GitHub Desktop.
Why numbering should start at one - representation class PHP
class SenseArr implements ArrayAccess
{
public function offsetSet($key, $value)
{
if (count($this->arr) == 0 && $key == null) {
$this->arr[1] = $value;
return;
}
$this->arr[$key] = $value;
}
public function offsetGet($key)
{
return $this->offsetExists($key) ? $this->arr[$key] : null;
}
public function offsetExists($key)
{
return isset($this->arr[$key]);
}
public function offsetUnset($key)
{
unset($this->arr[$key]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment