html - How to print out Multi-Dimensional Arrays in php -


consider array is:

array     (     [page-1] => array         (             [0] => array                 (                     [0] => cat-1                     [1] => item-1                 )         )     [page-2] => array         (             [0] => array                 (                     [0] => cat-2                     [1] => item-2                 )             [1] => array                 (                     [0] => cat-3                     [1] => item-3                 )             [2] => array                 (                     [0] => cat-4                     [1] => item-4                 )         )     [page-3] => array         (             [0] => array                 (                     [0] => cat-5                     [1] => item-5                 )         )     [page-4] => array         (             [0] => array                 (                     [0] => cat-6                     [1] => item-6                 )         )     [page-5] => array         (             [0] => array                 (                     [0] => cat-7                     [1] => item-7                 )             [1] => array                 (                     [0] => cat-9                     [1] => item-9                 )         )     [page-6] => array         (             [0] => array                 (                     [0] => cat-8                     [1] => item-8                 )         ) ) 

where, first keys [page-x] array main-links in navigation menu.
of main links may have sub-links, not.
sub-links values of key [0] of 3rd sub-array.
, url each , every link value of key [1] of 3rd sub-array.

pages have more 1 category show categories sub-links

the navigation bar have:

1. <a href="item-1">page-1</a> 2. <a href="#">page-2</a>      <a href="item-2">cat-2</a>      <a href="item-3">cat-3</a>      <a href="item-4">cat-4</a> 3. <a href="item-5">page-3</a> 4. <a href="item-6">page-4</a> 5. <a href="#">page-5</a>      <a href="item-7">cat-7</a>      <a href="item-9">cat-9</a> 6. <a href="item-8">page-6</a> 

the php code

$records = $p->main_links();  foreach ($records $key => $value) {     $return[$value['page']][] = array($value['child'], $value['item']); }  foreach ($return $key2 => $value2) {      $count = 0;      /* select specific value within array */     $main_links = $value2[$count][1]; /* url of main pages */      $count = count($return[$key2]);      if($count > 1) {         foreach ($value2 $key3 => $value3)         {             $link_name = $value3[0]; /* child link names */             $link_url  = $value3[1]; /* url of child links */              /* addedd htmlspecialchars() function $variables echoed html. provides xss protection */                             $cat_link .= '<li><a href="'.htmlspecialchars($filter1.$p->seourl($key2).$filter2.$p->seourl($link_url)).'">'.htmlspecialchars($link_name).'</a></li>';         }          $result .= '             <li '.htmlspecialchars($li_class).'><a href="#"><span>'.htmlspecialchars($key2).'</span></a>                 <ul>                     '.$cat_link.'                 </ul>             </li>';     }else {         $result .= '             <li><a href="'.htmlspecialchars($filter1.$p->seourl($main_links)).'"><span>'.htmlspecialchars($key2).'</span></a></li>';     } } 

unfortunately can't work... output not expecting :(
current output (wrong one):

1. <a href="item-1">page-1</a> 2. <a href="#">page-2</a>      <a href="item-2">cat-2</a>      <a href="item-3">cat-3</a>      <a href="item-4">cat-4</a> 3. <a href="item-5">page-3</a> 4. <a href="item-6">page-4</a> 5. <a href="#">page-5</a>      <a href="item-2">cat-2</a>      <a href="item-3">cat-3</a>      <a href="item-4">cat-4</a>      <a href="item-7">cat-7</a>      <a href="item-9">cat-9</a> 6. <a href="item-8">page-6</a> 

any appreciated!

your current code close working. line produce count of 1.

$count = count($value); 

what you're looking there, believe, is:

$count = count($return[$key]); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -