Saturday, February 7, 2009, 4:46:35 PM, Daniel wrote: > Just add an else statement that creates the that key, then point to > that key for the next iteration.
> //This changes the pointer to the leaf > foreach($query as $i) { > if(isset($pointer[$i])) > $pointer = &$pointer[$i]; > else { > $pointer[$i] = ""; > $pointer = &$pointer[$i]; > } Thanks! It nearly worked. But the last element was always added as [last] => array ( 'last' => 'value') instead of just 'last' => 'value' because the else condition gets hit with every last element. So I added a condition so the last iteration will not process the 'else'. It looks like that in my code: foreach ($keys as $i => $k) { if (isset($arr[$k])) $arr = &$arr[$k]; else { if ($i < count($keys)-1) { $arr[$k] = ''; $arr = &$arr[$k]; } } } > I should probably ask if this is for a PmWiki recipe or something > having to do with PmWiki. It's become quite a long thread, and this > mailing list is for PmWiki development discussions. So if it's just a > general php question, it might be better to continue our discussion > elsewhere. I am working on a PmWiki recipe for processing multi-dimensional arrays or data trees. Hans _______________________________________________ pmwiki-devel mailing list pmwiki-devel@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-devel