Q:

PHP: Delete Value of Array with Dynamic Key

A bit unusual use-case but maybe you can help:
I have the keys of an value as a separate array. It is pretty easy to get the value of the array with it like this: 
function whatEver(){

    $array = array(
        0 => array( 'other' ),
        1 => array(
            0 => array( 'other' ),
            1 => array( 'value' )
        ),
    );

    $keys = array(
        0 => '1',
        1 => '1'
    );

    $result = $array;

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

    return $result;
}

This will return the correct array/value:
Array
(
    [0] => value
)

But what if I want to delete this value (like unset($array[1][1])) from the original array and return the original $array without the value?

A:

If you need this to work for an arbitrary number of keys, you'll need to assign $result by reference on each iteration, and unset at the final step:
$result = &$array;
$last = array_pop($keys);

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

unset($result[$last]);

Note that you need to treat the final key slightly differently (the one stored in $last). If you just set a reference down to the last level, the unset will only remove the reference, not the actual element.
See https://3v4l.org/0a5Nv

