<?php
$_vars = array ();
function get ($name, $indices = array ())
{
global $_vars;
if (!isset ($_vars[$name]))
return null;
$value =& $_vars[$name];
foreach ($indices as $index)
{
if (!isset ($value[$index]))
return null;
$value =& $value[$index];
}
return $value;
}
function set ($name, $indices, $value)
{
global $_vars;
$array =& $_vars;
foreach ($indices as $index)
{
if (!isset ($array[$name]))
$array[$name] = array ();
$array =& $array[$name];
$name = $index;
}
$array[$name] = $value;
}
set ('test1', array (), 1);
set ('test2', array ('i1'), 'v1');
set ('test2', array ('i2'), 'v2');
set ('test3', array ('i1', 'j1'), 'v11');
set ('test3', array ('i1', 'j2'), 'v12');
set ('test3', array ('i2', 'j1'), 'v21');
set ('test3', array ('i2', 'j2'), 'v22');
var_dump (get ('test1', array ()));
var_dump (get ('test2', array ('i1')));
var_dump (get ('test2', array ('i2')));
var_dump (get ('test3', array ('i1', 'j1')));
var_dump (get ('test3', array ('i1', 'j2')));
var_dump (get ('test3', array ('i2', 'j1')));
var_dump (get ('test3', array ('i2', 'j2')));
?>