Since you can't call unset on a referenced element, you need to use another trick:
function array_unset($str, &$arr)
{
$nodes = split("->", $str);
$prevEl = NULL;
$el = &$arr;
foreach ($nodes as &$node)
{
$prevEl = &$el;
$el = &$el[$node];
}
if ($prevEl !== NULL)
unset($prevEl[$node]);
return $arr;
}
$str = "baz->foo->boo";
array_unset($str, $arr);
In essence, you traverse the array tree but keep a reference to the last array (penultimate node), from which you want to delete the node. Then you call unset
on the last array, passing the last node as a key.