dynamic array key additions

prabhash

New Member
Here is my precode...\[code\]$keys = array('a', 'b', 'c', 'd');$number = 10;\[/code\]And here is my code...\[code\]eval('$array[\''.implode('\'][\'',$keys).'\'] = $number;');\[/code\]Using this, I get the following result...\[code\]Array ( [a] => Array ( => Array ( [c] => Array ( [d] => 10 ) ) ))\[/code\]Now, the problem is that this is the exact result I want, but I don't want to use \[code\]eval()\[/code\]. As input to my code, I have a list of \[code\]keys\[/code\] and a \[code\]number\[/code\]. The \[code\]number\[/code\] should be set to the value of the \[code\]keys\[/code\] array being used to generate child-based \[code\]keys\[/code\] for a certain array \[code\]$array\[/code\].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 - \[code\]eval()\[/code\] preserves this already, so my new code should do the same.
 
Back
Top