I'm writing a PHP script in which I got a multidimensional array without fixed depth. Eg:
$myArray = [ 'item01' => [ 'section01' => [ 'part01' ] ], 'item02' => [ 'section02' => [ 'part02' => [ 'something01' ] ] ], 'item03' => [ 'section03' ] ] I have a string that contains the path to the value that should be changed. Eg:
$myPath = 'item02/section02/part02' And I have the new value:
$myValue = 'somethingElse' What I'm trying to do, is go through array $myArray following the path set in $myPath to change the value to $myValue.
The expected output, with the examples above, would be this:
$myArray = [ 'item01' => [ 'section01' => [ 'part01' ] ], 'item02' => [ 'section02' => [ 'part02' => [ 'somethingElse' ] ] ], 'item03' => [ 'section03' ] ] I've tried several ways, but keep getting stumped on this. In the end, it always reaches a point where the solution is, at its core, the same. Rubber duckying didn't help either. Other programmers I know, haven't been able to find a solution either.
I'm hoping someone here can at least provide some fresh ways to look into this.
PS: Everything above is in pseudo-code, as this problem doesn't seem to be language-specific.