precode: $keys = array('a', 'b', 'c', 'd'); $number = 10;
code: eval('$array[\''.implode('\'][\'',$keys).'\'] = $number;');
result:
Array (
[a] => Array
(
[b] => Array
(
[c] => Array
(
[d] => 10
)
)
)
)
problem: this is the exact result I want. Exactly! 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 (in this case called $array).
I DONT want to use eval though. I hate it. It's a hack and I want to write it proper, but after 8 hours (literally) of playing around with this, I've come to my end. A few resolutions I came up with produced this desired data set, but the nice thing about using eval us that it preserves the value of the array before hand. So it $array has some other values in it, it's not just going to overwrite them with my new keys/number. That's the part that gave me so much trouble.
Any help would be REALLY appreciate. Thanks dudes.