- print_r: documentation ( source)
- array_shift: documentation ( source)
- explode: documentation ( source)
<?php
function forget(&$array, $keys)
{
$original =& $array;
foreach ((array) $keys as $key)
{
$parts = explode('.', $key);
while (count($parts) > 1)
{
$part = array_shift($parts);
if (isset($array[$part]) && is_array($array[$part]))
{
$array =& $array[$part];
}
}
unset($array[array_shift($parts)]);
// clean up after each pass
$array =& $original;
}
}
print_r(forget(['a' => 0, 'b' => 'd']), ['b']);