query($sql); $area_array = $result->fetchAll(PDO::FETCH_ASSOC); writeLog($sql); foreach ($area_array as $k => $v) { $array_info = $v; unset($array_info['bus_type']); unset($array_info['res_id']); unset($array_info['res_name']); $area_parent = $v['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[$v['area_id']] = $v; if ($v['bus_type'] == 0 || $v['bus_type'] == 255) { $area_type_array[255][$v['area_id']] = $array_info; $area_type_array[255][$v['area_id']]['type'] = "area"; if (!empty($area_parent[0])) { $area_id_parent255 = array_merge($area_id_parent255, $area_parent); $res_id255[$v['res_id']]['area_id'] = $v['res_id']; $res_id255[$v['res_id']]['area_name'] = $v['res_name']; $res_id255[$v['res_id']]['type'] = "res"; $res_id255[$v['res_id']]['parent_area_id'] = $array_info['area_id']; } } else { $area_type_array[256][$v['area_id']] = $array_info; $area_type_array[256][$v['area_id']]['type'] = "area"; if (!empty($area_parent[0])) { $area_id_parent256 = array_merge($area_id_parent256, $area_parent); $res_id256[$v['res_id']]['area_id'] = $v['res_id']; $res_id256[$v['res_id']]['area_name'] = $v['res_name']; $res_id256[$v['res_id']]['type'] = "res"; $res_id256[$v['res_id']]['parent_area_id'] = $array_info['area_id']; } } } $area_id_parent255 = array_unique($area_id_parent255); asort($area_id_parent255); $area_id_parent255 = array_merge($area_id_parent255); $area_id_parent256 = array_unique($area_id_parent256); asort($area_id_parent256); $area_id_parent256 = array_merge($area_id_parent256); $sql = "select area_id,area_name,parent_area_id_list,area_level from base_area_view where area_id in (" . implode(",", $area_id_parent255) . ")"; $result = $pdo->query($sql); $area_array_parent255 = $result->fetchAll(PDO::FETCH_ASSOC); foreach ($area_array_parent255 as $k => $v) { $list_id = $v['parent_area_id_list']; $list = explode('}{', $list_id); $list = str_replace('{', '', $list); $list = str_replace('}', '', $list); $area_array_parent255[$k]['parent_area_id_list'] = $list; } $sql = "select area_id,area_name,parent_area_id_list,area_level from base_area_view where area_id in (" . implode(",", $area_id_parent256) . ")"; $result = $pdo->query($sql); $area_array_parent256 = $result->fetchAll(PDO::FETCH_ASSOC); foreach ($area_array_parent256 as $k => $v) { $list_id = $v['parent_area_id_list']; $list = explode('}{', $list_id); $list = str_replace('{', '', $list); $list = str_replace('}', '', $list); $area_array_parent256[$k]['parent_area_id_list'] = $list; } // print_r($area_array_parent255);die; // 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; $area_type_array[$area_type][$v['area_id']]['type'] = 'area'; } } 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; $area_type_array[$area_type][$v['area_id']]['type'] = 'area'; } } ksort($area_type_array[$area_type]); } foreach ($area_type_array[$area_type] 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'] = ''; $area_type_array[$area_type][$area_key]['parent_area_id_list'] = implode(",", $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']); } else { unset($area_type_array[$area_type][$k]['son']); } } if ($area_type == 255) { foreach ($res_id255 as $v) { $area_name[] = $v['area_name']; } foreach ($area_type_array[$area_type] as $k => $v) { if (in_array($v['area_name'], $area_name)) { unset($area_type_array[$area_type][$k]); } } $final[$area_type]['area'] = $area_type_array[$area_type]; $final[$area_type]['res'] = $res_id255; } else { foreach ($res_id256 as $v) { $area_name[] = $v['area_name']; } foreach ($area_type_array[$area_type] as $k => $v) { if (in_array($v['area_name'], $area_name)) { unset($area_type_array[$area_type][$k]); } } $final[$area_type]['area'] = $area_type_array[$area_type]; $final[$area_type]['res'] = $res_id256; } } //$array_final = $final; //print_r($final); set_memcache('ARY_LINE_POI_RES', $final); ?>