PHP Populating a multi-dimensional array -


i trying make array in type of format

array (     [name] => 'nick'     [email] => 'nick@email.com'     [groups] => array (         [0] => 'group1'         [1] => 'group2'         [2] => 'group3'     ) ) 

name , email contain 1 value. groups contain multiple values (different people).

so in loop defined so

foreach($result $info) {  } 

now $info variable contains lot of data, lots of users. name , email of each user, can do

$name = $info["name"][0]; $email = $info["email"][0]; 

i can start building array attempting make

$userdata = array(     "name" => $name,     "email" => $email ); 

to groups, need do

foreach($info["group"] $group) {     print_r($group["name"]);     } 

my code @ moment looks following $userdata = array();

foreach($result $info) {      $name = $info["disname"][0];     $email = $info["email"][0];      $userdata = array(         "name" => $name,         "email" => $email     );      foreach($info["group"] $group) {         print_r($group["name"]);     }  } 

how can data extracting array in format need?

thanks

modify code..

foreach($result $info) {      $name = $info["disname"][0];     $email = $info["email"][0];      $userdata = array(         "name" => $name,         "email" => $email     );      foreach($info["group"] $group) {         $groups[] = $group;     }      $userdata['group'] = $groups;  } 

$groups array index $userdata['group']


Comments

Popular posts from this blog

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

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -