This is my watch
How to get
such an array? Thank you
This is my watch
How to get
such an array? Thank you
There is a group_concat function in Mysql, you can try it.
The approximate sql statement is as follows:
<code>SELECT term_id, group_concat(village_name) as area FROM tb_name GROUP BY term_id;</code>
<code>$data=array(); foreach(数据库数组 as $v){ if(!isset($data[$v['team_id']])){ $data[$v['team_id']]=$v['village_name']; }else{ $data[$v['team_id']].=','.$v['village_name']; } } $d=array(); foreach($data as $kk=>$vv){ $d[]=array( 'team_id'=>$kk, 'area'=>$vv, ); } unset($data); var_dump($d); </code>