$mylist = array( array( 'area_parent_id'=>0,'id'=>1,'area_name' => '河北',), array( 'area_parent_id'=>0,'id'=>2,'area_name' => '山东',), array( 'area_parent_id'=>0,'id'=>3,'area_name' => '辽宁',), array( 'area_parent_id'=>2,'id'=>4,'area_name' => '济南',), array( 'area_parent_id'=>2,'id'=>5,'area_name' => '德州',), array( 'area_parent_id'=>3,'id'=>6,'area_name' => '沈阳',), array( 'area_parent_id'=>3,'id'=>7,'area_name' => '大连',), array( 'area_parent_id'=>4,'id'=>8,'area_name' => '济南县1',), array( 'area_parent_id'=>5,'id'=>9,'area_name' => '德州县1',), array( 'area_parent_id'=>5,'id'=>10,'area_name' => '德州县2',) ); $arr = array ( 1 => array ( 'area_name' => '河北', 'area_parent_id' => '0', ), 2 => array ( 'area_name' => '山东', 'area_parent_id' => '0', ), 3 => array ( 'area_name' => '石家庄','area_parent_id' => '1',), 4 => array ( 'area_name' => '唐山','area_parent_id' => '1'), 5 => array ( 'area_name' => '济南','area_parent_id' => '2'), 6 => array ( 'area_name' => '青岛','area_parent_id' => '2'), ); function moreList($arr, $p_id){ //数据层级化, $r = array(); foreach($arr as $key=>$val){ if($val['area_parent_id'] == $p_id) { $length = count($r);//0 $r[$length] = $val; if($t = moreList($arr,$val['id'])){//$key $r[$length]['children'] = $t; } } } return $r; } echo '<pre>'; print_r(moreList($mylist,0));//$arr
echo '</pre>';