foyleman Posted November 17, 2007 Share Posted November 17, 2007 I am having trouble properly setting a dynamic variable that should be part of an array. basically, I want to set this: ${"one[a]"} = '123'; If I echo the result, it looks good: $one[a] = 123; But when I check $GLOBALS, I see: [one[a]] => 123 I worked out an example in case someone can help. $testar = array( 'one' => array( 'a' => '123', 'b' => '456' ) ); print_r($GLOBALS); dec_array($testar); print_r($GLOBALS); function dec_array($arr, $kroot='') { foreach($arr as $key => $val) { if(!empty($kroot)) { $key = $kroot."[".$key."]"; } if(is_array($val)) { dec_array($val, $key); } else { global ${$key}; ${$key} = $val; } } return; } What I want to see is this: [one] => Array ( [a] => 123 => 456 ) But what I actually see is this: [one[a]] => 123 [one] => 456 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.