query($sql); //低级POI数组 $area_array = $result->fetchAll(PDO::FETCH_ASSOC); //以穿梭,直通区分的POI数组 $area_type_array = array(); //以id为索引的低级POI数组 $area_id_array = array(); //高级POI数组 $area_id_parent255 = array(); $area_id_parent256 = array(); foreach($area_array as $v => $k){ $array_info = $k; unset($array_info['bus_type']); $area_parent = $k['parent_area_id_list']; $area_parent = explode('}{',$area_parent); $area_parent = str_replace('{','',$area_parent); $area_parent = str_replace('}','',$area_parent); $array_info['parent_area_id_list'] = $area_parent; //$area_id_array[$k['area_id']] = $k; if($k['bus_type'] == 0 || $k['bus_type'] == 255 ){ $area_type_array[255][$k['area_id']] = $array_info; if(!empty($area_parent[0])){ $area_id_parent255 = array_merge($area_id_parent255,$area_parent); } }else{ $area_type_array[256][$k['area_id']] = $array_info; if(!empty($area_parent[0])){ $area_id_parent256 = array_merge($area_id_parent256,$area_parent); } } } $area_id_parent255 = array_unique($area_id_parent255); asort($area_id_parent255); sort($area_id_parent255); $area_id_parent256 = array_unique($area_id_parent256); asort($area_id_parent256); sort($area_id_parent256); $sql = "select id as area_id,area_name from base_area where id in (" . implode(",",$area_id_parent255) . ")"; $result=$pdo->query($sql); $area_array_parent255 = $result->fetchAll(PDO::FETCH_ASSOC); $sql = "select id as area_id,area_name from base_area where id in (" . implode(",",$area_id_parent256) . ")"; $result=$pdo->query($sql); $area_array_parent256 = $result->fetchAll(PDO::FETCH_ASSOC); //print_r($area_array_parent255); //print_r($area_array_parent256); foreach($area_type_array as $area_type => $area_type_info){ if($area_type == 255){ foreach($area_array_parent255 as $v){ if(!isset($area_type_info[$v['area_id']])){ $area_type_array[$area_type][$v['area_id']] = $v; } } ksort($area_type_array[$area_type]); }else{ foreach($area_array_parent256 as $v){ if(!isset($area_type_info[$v['area_id']])){ $area_type_array[$area_type][$v['area_id']] = $v; } } ksort($area_type_array[$area_type]); } foreach($area_type_info as $area_key => $area_value){ if(count($area_value) > 0){ foreach($area_value['parent_area_id_list'] as $key => $value){ if(!empty($value)){ $area_type_array[$area_type][$value]['son'][] = $area_value['area_id']; } } $area_type_array[$area_type][$area_key]['son'] = ''; unset($area_type_array[$area_type][$area_key]['parent_area_id_list']); } } foreach($area_type_array[$area_type] as $k => $v){ if($v['son'] != ''){ $area_type_array[$area_type][$k]['son'] = implode(',',$v['son']); } } } set_memcache('ARY_LINE_POI', $area_type_array ); ?>