The array is multi-dimensional and has a variable number of sub-keys, like
$arr[$a][$b][$c] = \'X\';
3 in this case. I want to create a function
Here is a recursive approach to your problem:
function removeByStr($key, &$arr)
{
if(!is_array($key))
{
$key = explode(".", $key);
}
$i = array_shift($key);
if(count($key) == 0)
{
if(!isset($arr[$i]))
{
return;
}
unset($arr[$i]);
}
else if(isset($arr[$i]) && is_array($arr[$i]))
{
removeByStr($key, $arr[$i]);
}
}