$items = array(
1 => array('id' => 1, 'pid' => 0, 'name' => '江西省'),
2 => array('id ' => 2, 'pid' => 0, '黒竜江省'),
3 => 3, 'pid' => ' name' => '南昌市'),
4 => array('id' => 4, 'pid' => 2, 'name' => 'ハルビン市'),
5 => ; array('id' => 5, 'pid' => 2, 'name' => '集西市'),
6 => array('id' => 6, 'pid' = > 4, '名前' => '祥坊区'),
7 => array('id' => 4, '名前' => '南港区' ) ,
8 => array('id' => 8, 'pid' => 6, 'name' => '六角路'),
9 => array('id' => 9 , 'pid' => 7, 'name' => 'Xidazhi Street'),
10 => array('id' => 10, 'name ' => '東北林業大学'),
11 => array('id' => 11, 'pid' => 9, 'name' => 'ハルビン工業大学'),
12 = > 配列('id' => 12, 'pid' => 8, 'name' => 'ハルビン師範大学'),
13 => array('id' => 13, 'pid ' => ; 1, '名前' => '甘州市'),
14 => array('id' => 14, 'pid' => '甘県 '),
15 => array('id' => 15, 'pid' => 13, 'name' => 'Yudu County'),
16 => array('id' = > 16, 'pid' => 14, 'name' => 'Maodian Town'),
17 => array('id' => 14, 'name ' => '大田郷'),
18 => array('id' => 18, 'pid' => 16, 'name' => '宜源村'),
19 => array('id' => 19, 'pid' => '名前' =>
);
function genTree5($items) {
foreach ($items として)
$items[$item['pid']]['son'][$item['id']] = &$items[$item['id']]; return isset ($items[0]['息子']) ? $items[0]['息子'] : array();
方法 2:
function findChild($arr,$id){
$childs= array(); arr as $k => $v){
if($v['pid']== $id){
$childs[]=$v;
}
}
/ / echo "
" ;print_r($childs);die();
return $childs;
function build_tree($root_id){
$childs =array(); root_id);
// print_r($childs);
if(empty($childs)){
return null;
foreach ($childs as $k => $v){
k => }
}
$childs を返す
}