I have multidimensional map (collection) $data in PHP hack. I want to search for a key 'road' and replace its value with
map{ 'test' => abc};
I have key arrays as
$keys = ['meta', 'attr', 'road'];
below is my Map
$data = Map {'meta' => Map {
'time' => 11.364,
'count' => 3,
'attr' => Map {
'id'=> 7845,
'road' => Map {
'length' => 'km',
'width' => 'm'
}
}
},
'Assets' => [15,78,89]
};
I was trying below code but give me Error:
$keys = ['meta','attr'];
$arr = &$data;
foreach($keys as $key)
{
$arr = &$arr[$key];
}
$arr = map{ 'test' => abc};
Any thoughts how can I implement search and replace algorithm?