I am trying here to set the vale of the first child element of $map. I need to do this by referencing the path of the array i.e [0]['child'].
The function returns the path value ok if set but I am having trouble changing the value of that of that element. So in this case I want $map[0]['child'] to equal "new".
function getArrayPath($arr,$path) {
foreach($path as $item){
$arr = $arr[$item];
}
return $arr;
}
$map='[{"child":""},{"child":""},{"child":""}]';
$map=json_decode($map,true);
$path = array("0","child");
$target = getArrayPath($map,$path);
if($target==""){
$target="new";
}
var_dump($map);