How to display title and subtitle in foreach - PHP -


i having following array format:

array (     [0] => array        (             [title] => main cat             [subfield] => array               (                 [1] => array                     (                                                     [sub_title] => sub cat 1                     )                  [2] => array                     (                                                     [sub_title] => sub cat 2                     )                 )          )        [1] => array         (             [title] => main cat 2             [subfield] => array               (                 [1] => array                     (                                                     [sub_title] => test cat 1                                                 )                  [2] => array                     (                                                     [sub_title] => test cat 2                     )                 )          ) 

i need display in following format using foreach using php. o/p:

main cat   sub cat 1   sub cat 2  main cat 2   test cat 1   test cat 2 

how can done... in advance...

edit : try is

 $f = 1;       foreach($vars['fields'] $value) {          $vars['topic_main'][] = $value['title']."<br>&nbsp;".$value['subfield'][$f]['sub_title']."<br>";          $f++;       }        $vars['title'] = implode(' ' ,$vars['topic_main']); 

my o/p is

main cat   sub cat 1    main cat 2   test cat 1 

assuming array called categories. (edit: $vars['fields'] )

foreach($vars['fields'] $cat){      echo $cat['title'].'<br/>';     foreach($cat['subfield'] $sub){         echo $sub['subtitle'].'<br/>';     } } 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -