<?php
function delete(array &$array, string $key): bool
{
// process the parts
$target =& $array;
// split the key in it's parts
$key_parts = explode('.', $key);
while ( ! empty($key_parts))
{
// check if this key exists, and bail out if it doesn't
if ( ! array_key_exists($key_parts[0], $target))
{
return false;
}
// change the target
$target =& $target[$key_parts[0]];
// and on to the next key part
array_shift($key_parts);
}
// delete the target found
unset($target);
return true;
}
$arr = array('a' => array('b1' => array('c1' => 'value c1', 'c2' => 'value c2'), 'b2' => 'value b2'));
var_dump(delete($arr, 'a.b.c1'), $arr);