Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multidimensional ArrayAccess
<?php
class MultiArrayAccess implements ArrayAccess
{
public function offsetExists($offset)
{
echo " EXISTS ";
print_r($offset);
echo "\n";
}
public function offsetGet($offset)
{
echo " GET ";
print_r($offset);
echo "\n";
return $this;
}
public function offsetSet($offset, $value)
{
echo " SET ";
print_r($offset);
echo " ";
print_r($value);
echo "\n";
}
public function offsetUnset($offset)
{
echo " UNSET ";
print_r($offset);
echo "\n";
}
}
$multiArrayAccess = new MultiArrayAccess();
echo "EXISTS:\n";
isset($multiArrayAccess[1][2]);
echo "GET:\n";
$multiArrayAccess[3][4];
echo "SET:\n";
$multiArrayAccess[5][6] = 7;
echo "UNSET:\n";
unset($multiArrayAccess[8][9]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.