I have a multi-dimensional array that needs to be "searchable" based on provided keys that may represent multiple levels w/in the array and change that found value.
// array that needs to be searched
$array = [
'one' => [
'two' => [
'three' => 'four',
],
],
'five' => [
'six' => 'eight',
],
];
// array that represent the change
$change = [
'five|six' => 'seven',
];
I need to find $array['five']['six'] dynamically and change that value to the provided. There may be multiple changes and they could be of varying depths. Note: the arrays I am really using are larger and deeper,
Last attempt:
foreach ($change as $k => $v) {
$keyList = '';
$keys = explode('|', $k);
foreach ($keys as $key) {
$keyList .= '[' . $key . ']';
}
$array[$keyList] = $v;
// throws a notice: Notice: Undefined index (realize it is a string representation of keys.
// Tried some other ways but nothing is clicking
}