ar=array(0=>array('name'=>'food','id'=>1,'pid'=>0),
02 1 =>array('name'=>'植物','id'=>2,'pid'=>0),
03 3=>array('name'=>'キャベツ' ,'id'=>3,'pid'=>1),
04 4=>array('name'=>'tree','id'=>4,'pid'=> ;2),
05 5=>array('name'=>'Apple','id'=>5,'pid'=>3),
06 6=>array(' name'=>'パイン','id'=>6,'pid'=>4),
07 7=>array('name'=>'ドリンク','id'=> ;7,'pid'=>1),
08
09 9=>array('name'=>'テスト 2','id'=>9,'pid'=>8) , 10 10=>array('name'=> ;'People','id'=>10,'pid'=>9), 11 11=>array('name'= >'Xiaomi','id'=>11,' pid'=>0), 12 ); 13 14 echo '22 foreach ($tree as $key => $item)
23
25 =sonNum($tree,$item['id']);
27 echo '
31 }
32 //echo '
33 echo $item['name'];
34 echo '
35 tre($tree,$item['id']);
36 }
37 }
38 //tre($tree,$strid);
39 }
40
41 関数sonNum($tre,$sum,$totale=1)
42 {
43 foreach ($tre as $key => $value)
44 {
45 if ($value['pid'] == $sum){
46 $totale += SonNum($tre,$value['id'],1);
47 }
48 }
49 $tole を返します。
50 }