Building array reference with strings
Posted: Tue Jul 12, 2011 1:06 pm
I;m building a simple CMS system to learn more about PHP as work does not tax me. After much trial and error I've got a script working to collect children of children indefinitely and add them all into an array. My problem is I need to pass the array it's current location or else all new elements will be placed in the first array and not nested arrays for each child.
The function is called and passed the top level parent id of "-1". It all works fine apart from $this->page_list+$table_index = $child_arr[$c]['title'];
Just how do i construct and pass along my new location in the multidimensional array and pass this to the next iteration of the function so that the script knows where to insert the data?
Code: Select all
function test($parentID, $table_index='')
{
$child_arr = $this->query_database('', '', 'SELECT * FROM page WHERE parentID ='.$parentID);
$count_children = count($child_arr);
for($c=0; $c<$count_children; $c++)
{
$table_index .= '['.$c.']';
$this->page_list+$table_index = $child_arr[$c]['title'];
$this->test($child_arr[$c]['ID'], $c);
}
print_r($this->page_list);
//return $this->page_list;
}
Just how do i construct and pass along my new location in the multidimensional array and pass this to the next iteration of the function so that the script knows where to insert the data?