I'm trying to remove an element in a multidimensional array.
The element which is needs to be removed is given by a string like globals.connects.setting1
. This means I'm intend to modify an array like this:
// Old Array
$old = array(
"globals" => array(
"connects" => array(
"setting1" => "some value",
"setting2" => "some other value",
"logging" => array()),
"someOtherKey" => 1
));
// After modification
$new = array(
"globals" => array(
"connects" => array(
"setting2" => "some other value",
"logging" => array()),
"someOtherKey" => 1
));
Unfortunately I do not know either the "depth" of the given string nor the exact structure of the array. I'm looking for a function like unsetElement($path, $array)
which returns the array $new
, if the array $old
and globals.connects.setting1
is given as argument.
I'd like to avoid the use of the eval()
function due to security reasons.