Here is my precode...
$keys = array('a', 'b', 'c', 'd');
$number = 10;
And here is my code...
eval('$array[\''.implode('\'][\'',$keys).'\'] = $number;');
Using this, I get the following result...
Array (
[a] => Array
(
[b] => Array
(
[c] => Array
(
[d] => 10
)
)
)
)
Now, the problem is that this is the exact result I want, but I don't want to use eval().
As input to my code, I have a list of keys and a number. The number should be set to the value of the keys array being used to generate child-based keys for a certain array $array.
Is there a different way that I can achieve this? I don't want to overwrite the keys/numbers with new values as the code works - eval() preserves this already, so my new code should do the same.