PHP multi-dimensional array being added too -


having issue something. have array called result in following format:

array (     [count] => 74     [0] => array      (         [15] => usncreated         [memberof] => array         (             [count] => 3             [0] => groupa             [1] => groupb             [2] => groupc         )      )     [1] => array      (         [15] => usncreated         [memberof] => array         (             [count] => 2             [0] => groupa             [1] => groupf         )      ) ) 

i trying build own array now. @ moment have

foreach($result $user) {      if(isset($user["memberof"])){         foreach($user["memberof"] $group) {             $groups[] = $group;         }       }      $userdata["group"] = $groups;       print_r("<pre>");         print_r($userdata);      print_r("</pre>");  } 

problem output so

array (     [group] => array     (         [0] => 2         [1] => groupa         [2] => groupb     ) )  array (     [group] => array     (         [0] => 2         [1] => groupa         [2] => groupb         [3] => 2         [4] => groupa         [5] => groupf     ) ) 

so second 1 repeats first. if move print_r somewhere else, outside loop, see 1 user every possible group. know needs print in loop, whatever try cant correct output.

how can display groups each user?

thanks

foreach($result $user) {      $groups = array(); // reset groups array      if(isset($user["memberof"])){         foreach($user["memberof"] $group) {             $groups[] = $group;         }       }      $userdata["group"] = $groups;       print_r("<pre>");         print_r($userdata);      print_r("</pre>");  } 

reset groups array each user found in results.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

android - How to create dynamically Fragment pager adapter -