Prestashop horizontal navigation PHP multidimentional array
===

I just started working with prestashop/PHP and I am trying to create a horizontal navigation module.  I am running into a problem displaying unique categories with their associated subcategories.  I have duplicate values. I would like e.g., Category 5 maps to subcategories 6,7.

Here is example output when I dump the array to the screen:

array(4) { [0]=> string(1) "5" [1]=> array(1) { [0]=> string(15) "Test Category 2" } [2]=> string(1) "5" [3]=> array(1) { [0]=> string(13) "Test Category" } } array(3) { [0]=> string(1) "6" [1]=> string(4) "test" [2]=> string(1) "5" }

This is my code in the module:

     public function hookNavigation($params)
  	{
  		global $smarty;
		$sql = "SELECT DISTINCT c.id_category parent, c2.id_category child, l.name,       l.link_rewrite
     FROM "._DB_PREFIX_."category c
     LEFT OUTER JOIN "._DB_PREFIX_."category c2 ON c.id_category = c2.id_parent
     INNER JOIN "._DB_PREFIX_."category_lang l ON c.id_category = l.id_category
     WHERE c.id_category <>1
     AND c.active =1
     AND c.level_depth <2
     ORDER BY c.id_category ASC ";
		$test = array();
		$children = array();
		if($results = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql))
		{
			foreach ($results as $row) {
				if($row['child'] != NULL) {
					$sqlChild = "SELECT DISTINCT ps_category.id_category, name, link_rewrite
								FROM ps_category
								INNER JOIN ps_category_lang ON ps_category.id_category = ps_category_lang.id_category
								WHERE ps_category.id_category=".$row['child'];
					$resultChild = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sqlChild);
					foreach ($resultChild as $childRow) {
						array_push($children, $row['parent'], array($childRow['name']));
					}
					
				} else {
					array_push($test, $row['parent'], array('test'));
				}
			}
		}
		$sum = array_merge($test, $children);
		$output = iterator_to_array(new RecursiveIteratorIterator(
    new RecursiveArrayIterator($sum)), FALSE);
		var_dump($children);
		var_dump($output);
	    $smarty->assign('test', $output);
  		return $this->display(__FILE__,'nav.tpl');
  	}

In the nav.tpl file I have the following:

     <h3>Code from the module...</h3>
		{foreach from=$test item=cat}
			{$cat}<br/>
			{foreach from=$cat item=sub}
				{$sub} <br />
			{/foreach}
		{/foreach}<br />

This is what is outputted to the screen:

Code from the module...

6
6 
test
test 
5
5 
Test Category 2
Test Category 2 
5
5 
Test Category
Test Category 

I would appreciate any help/suggestions.