Q:

Unset deep session variable dynamic

My session class set a session dynamic deep:
simplified:
$keys = "test.deep.more";
$keys = explode(".", $keys);
$current = &$_SESSION;
foreach($keys as $key) {
  $current = &$current[$key];
}

Output is:
Array
(
  [test] => Array
    (
        [deep] => Array
            (
                [more] => 
            )

    )

)

But, how can I unset a variable?
unset($current)

does not work. $current is currently null, because more has no value.
Anyone a idea?
EDIT:
To be more clear: I need a way to unset a dynamic deep session array. My try:
$session = &$_SESSION;

foreach($keys as $key) {
  $session = &$session[$key];
}

unset($session);

Or does a unset() for a reference not work?
EDIT2:
Anyone a idea how i can dynamic create a function that unset a deep session? Without typing
 unset($_SESSION['test']['deep']['more'])

A:

You cannot unset the referenced variable.
As per the documentation

When you unset the reference, you just break the binding between variable name and variable content. This does not mean that variable content will be destroyed

For example;
<?php

$a = 1;
$b =& $a; //Assign $a to $b by reference
unset($b); //Unset $b (hoping to unset $a)

var_dump($a); //This prints
var_dump($b); //$b doesn't exist

?>

https://eval.in/198105
To accomplish your task
unsetDeep($_SESSION, 'more');
function unsetDeep(&$array, $findKey) {
  foreach ($array as $key => &$value) {
    if (is_array($value) AND $key != $findKey) {
      unsetDeep($value, $findKey);
    } else {
      if ($key == $findKey){
        unset($array[$key]);
      }
    }
  }
}

