Building array reference with strings

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ralliare
Forum Newbie
Posts: 1
Joined: Tue Jul 12, 2011 1:01 pm

Building array reference with strings

Post by Ralliare »

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.

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;	
		}
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?
Post Reply