#html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>省市联动</h1>
www.php.cn<a href="http://www.php.cn">欢迎你</a>
<hr>
省:
<select name="province" id="province">
<option value="">==请选择==</option>
</select>
</body>
市:
<select name="city" id="city">
<option value="">==请选择==</option>
</select>
<script type="text/javascript">
/**
* 获取所有省,添加到
* <select name="province" id="province">
* 添加change
* 获取当前选择的省Id
* 使用省id,得到该省下所有市
* 把所有市添另到
* <select name="city" id="city">
*/
function createXMLHttpRequest(){
try{
return new XMLHttpRequest();
}catch (e) {
try {
return new ActiveXObject('Msxml2.XMLHTTP');
}catch (e) {
return new ActiveXObject('Microsoft.XMLHTTP');
}
}
}
window.onload = function(){
//发送异步请求,得到所有省.
var xmlHttp = createXMLHttpRequest();
//打开链接
xmlHttp.open('GET','http://www.php7.cn/china/ProvinceControl.php', true);
//发送
xmlHttp.send(null);
//添加监听
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
//alert(xmlHttp.responseText);
var proArray = eval("(" + xmlHttp.responseText + ")");
for (var i=0; i<proArray.length; i++){
var pro = proArray[i];//
//创建标签元素
var optionELe = document.createElement('option');
//给option元素的 value赋值
optionELe.value = pro.pid;
var textNode = document.createTextNode(pro.pname);
optionELe.appendChild(textNode);
//把opiton元素添加select元素中
document.getElementById('province').appendChild(optionELe);
}
}
}
};
//添加change事件
document.getElementById('province').onchange = function(){
//从服务器得到选择的省下的市
var xmlHttp = createXMLHttpRequest();
xmlHttp.open('POST','http://www.php7.cn/china/CityControl.php', true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send('pid='+ this.value);//用户选择的值 .
//添加监听
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
/**
* 清空原来的option
* 得到服务器发送过来的所有市
* 生成option.
*/
//清空select id='city'>
var citySelect = document.getElementById('city');
//获取的有子元素
var cityOptionArray = citySelect.getElementsByTagName('option');
while (cityOptionArray.length > 1){//控制循环次数
//只删除下标1
citySelect.removeChild(cityOptionArray[1]);
}
//得到所有市
var cityArray = eval("(" + xmlHttp.responseText +")");
//循环遍历.生成option
for (var i = 0; i < cityArray.length; i++){
var city = cityArray[i];//
//创建标签元素
var optionELe = document.createElement('option');
//给option元素的 value赋值
optionELe.value = city.cid;
var textNode = document.createTextNode(city.cname);
optionELe.appendChild(textNode);
//把opiton元素添加select元素中
citySelect.appendChild(optionELe);
}
}
}
}
}
}
</script>
</html>
//city代码
<?php
$city = [
['cid'=>1,'cname'=>'东城区','pid'=>1],
['cid'=>2,'cname'=>'西城区','pid'=>1],
['cid'=>3,'cname'=>'崇文区','pid'=>1],
['cid'=>4,'cname'=>'宣武区','pid'=>1],
['cid'=>5,'cname'=>'朝阳区','pid'=>1],
['cid'=>6,'cname'=>'丰台区','pid'=>1],
['cid'=>7,'cname'=>'石景山区','pid'=>1],
['cid'=>8,'cname'=>'海淀区','pid'=>1],
['cid'=>9,'cname'=>'门头沟区','pid'=>1],
['cid'=>10,'cname'=>'房山区','pid'=>1],
['cid'=>11,'cname'=>'通州区','pid'=>1],
['cid'=>12,'cname'=>'顺义区','pid'=>1],
['cid'=>13,'cname'=>'昌平区','pid'=>1],
['cid'=>14,'cname'=>'大兴区','pid'=>1],
['cid'=>15,'cname'=>'怀柔区','pid'=>1],
['cid'=>16,'cname'=>'平谷区','pid'=>1],
['cid'=>17,'cname'=>'密云县','pid'=>1],
['cid'=>18,'cname'=>'延庆县','pid'=>1],
['cid'=>19,'cname'=>'和平区','pid'=>2],
['cid'=>20,'cname'=>'河东区','pid'=>2],
['cid'=>21,'cname'=>'河西区','pid'=>2],
['cid'=>22,'cname'=>'南开区','pid'=>2],
['cid'=>23,'cname'=>'河北区','pid'=>2],
['cid'=>24,'cname'=>'红桥区','pid'=>2],
['cid'=>25,'cname'=>'塘沽区','pid'=>2],
['cid'=>26,'cname'=>'汉沽区','pid'=>2],
['cid'=>27,'cname'=>'大港区','pid'=>2],
['cid'=>28,'cname'=>'东丽区','pid'=>2],
['cid'=>29,'cname'=>'西青区','pid'=>2],
['cid'=>30,'cname'=>'津南区','pid'=>2],
['cid'=>31,'cname'=>'北辰区','pid'=>2],
['cid'=>32,'cname'=>'武清区','pid'=>2],
['cid'=>33,'cname'=>'宝坻区','pid'=>2],
['cid'=>34,'cname'=>'宁河县','pid'=>2],
['cid'=>35,'cname'=>'静海县','pid'=>2],
['cid'=>36,'cname'=>'蓟县','pid'=>2],
['cid'=>37,'cname'=>'石家庄','pid'=>3],
['cid'=>38,'cname'=>'唐山','pid'=>3],
['cid'=>39,'cname'=>'秦皇岛','pid'=>3],
['cid'=>40,'cname'=>'邯郸','pid'=>3],
['cid'=>41,'cname'=>'邢台','pid'=>3],
['cid'=>42,'cname'=>'保定','pid'=>3],
['cid'=>43,'cname'=>'张家口','pid'=>3],
['cid'=>44,'cname'=>'承德','pid'=>3],
['cid'=>45,'cname'=>'沧州','pid'=>3],
['cid'=>46,'cname'=>'廊坊','pid'=>3],
['cid'=>47,'cname'=>'衡水','pid'=>3],
['cid'=>48,'cname'=>'太原','pid'=>4],
['cid'=>49,'cname'=>'大同','pid'=>4],
['cid'=>50,'cname'=>'阳泉','pid'=>4],
['cid'=>51,'cname'=>'长治','pid'=>4],
['cid'=>52,'cname'=>'晋城','pid'=>4],
['cid'=>53,'cname'=>'朔州','pid'=>4],
['cid'=>54,'cname'=>'晋中','pid'=>4],
['cid'=>55,'cname'=>'运城','pid'=>4],
['cid'=>56,'cname'=>'忻州','pid'=>4],
['cid'=>57,'cname'=>'临汾','pid'=>4],
['cid'=>58,'cname'=>'吕梁','pid'=>4],
['cid'=>59,'cname'=>'呼和浩特','pid'=>5],
['cid'=>60,'cname'=>'包头','pid'=>5],
['cid'=>61,'cname'=>'乌海','pid'=>5],
['cid'=>62,'cname'=>'赤峰','pid'=>5],
['cid'=>63,'cname'=>'通辽','pid'=>5],
['cid'=>64,'cname'=>'鄂尔多斯','pid'=>5],
['cid'=>65,'cname'=>'呼伦贝尔','pid'=>5],
['cid'=>66,'cname'=>'巴彦淖尔','pid'=>5],
['cid'=>67,'cname'=>'乌兰察布','pid'=>5],
['cid'=>68,'cname'=>'兴安盟','pid'=>5],
['cid'=>69,'cname'=>'锡林郭勒盟','pid'=>5],
['cid'=>70,'cname'=>'阿拉善盟','pid'=>5],
['cid'=>71,'cname'=>'沈阳','pid'=>6],
['cid'=>72,'cname'=>'大连','pid'=>6],
['cid'=>73,'cname'=>'鞍山','pid'=>6],
['cid'=>74,'cname'=>'抚顺','pid'=>6],
['cid'=>75,'cname'=>'本溪','pid'=>6],
['cid'=>76,'cname'=>'丹东','pid'=>6],
['cid'=>77,'cname'=>'锦州','pid'=>6],
['cid'=>78,'cname'=>'营口','pid'=>6],
['cid'=>79,'cname'=>'阜新','pid'=>6],
['cid'=>80,'cname'=>'辽阳','pid'=>6],
['cid'=>81,'cname'=>'盘锦','pid'=>6],
['cid'=>82,'cname'=>'铁岭','pid'=>6],
['cid'=>83,'cname'=>'朝阳','pid'=>6],
['cid'=>84,'cname'=>'葫芦岛','pid'=>6],
['cid'=>85,'cname'=>'长春','pid'=>7],
['cid'=>86,'cname'=>'吉林','pid'=>7],
['cid'=>87,'cname'=>'四平','pid'=>7],
['cid'=>88,'cname'=>'辽源','pid'=>7],
['cid'=>89,'cname'=>'通化','pid'=>7],
['cid'=>90,'cname'=>'白山','pid'=>7],
['cid'=>91,'cname'=>'松原','pid'=>7],
['cid'=>92,'cname'=>'白城','pid'=>7],
['cid'=>93,'cname'=>'延边','pid'=>7],
['cid'=>94,'cname'=>'哈尔滨','pid'=>8],
['cid'=>95,'cname'=>'齐齐哈尔','pid'=>8],
['cid'=>96,'cname'=>'鸡西','pid'=>8],
['cid'=>97,'cname'=>'鹤岗','pid'=>8],
['cid'=>98,'cname'=>'双鸭山','pid'=>8],
['cid'=>99,'cname'=>'大庆','pid'=>8],
['cid'=>100,'cname'=>'伊春','pid'=>8],
['cid'=>101,'cname'=>'佳木斯','pid'=>8],
['cid'=>102,'cname'=>'七台河','pid'=>8],
['cid'=>103,'cname'=>'牡丹江','pid'=>8],
['cid'=>104,'cname'=>'黑河','pid'=>8],
['cid'=>105,'cname'=>'绥化','pid'=>8],
['cid'=>106,'cname'=>'大兴安岭','pid'=>8],
['cid'=>107,'cname'=>'黄浦区','pid'=>9],
['cid'=>108,'cname'=>'卢湾区','pid'=>9],
['cid'=>109,'cname'=>'徐汇区','pid'=>9],
['cid'=>110,'cname'=>'长宁区','pid'=>9],
['cid'=>111,'cname'=>'静安区','pid'=>9],
['cid'=>112,'cname'=>'普陀区','pid'=>9],
['cid'=>113,'cname'=>'闸北区','pid'=>9],
['cid'=>114,'cname'=>'虹口区','pid'=>9],
['cid'=>115,'cname'=>'杨浦区','pid'=>9],
['cid'=>116,'cname'=>'闵行区','pid'=>9],
['cid'=>117,'cname'=>'宝山区','pid'=>9],
['cid'=>118,'cname'=>'嘉定区','pid'=>9],
['cid'=>119,'cname'=>'浦东新区','pid'=>9],
['cid'=>120,'cname'=>'金山区','pid'=>9],
['cid'=>121,'cname'=>'松江区','pid'=>9],
['cid'=>122,'cname'=>'青浦区','pid'=>9],
['cid'=>123,'cname'=>'南汇区','pid'=>9],
['cid'=>124,'cname'=>'奉贤区','pid'=>9],
['cid'=>125,'cname'=>'崇明县','pid'=>9],
['cid'=>126,'cname'=>'南京','pid'=>10],
['cid'=>127,'cname'=>'无锡','pid'=>10],
['cid'=>128,'cname'=>'徐州','pid'=>10],
['cid'=>129,'cname'=>'常州','pid'=>10],
['cid'=>130,'cname'=>'苏州','pid'=>10],
['cid'=>131,'cname'=>'南通','pid'=>10],
['cid'=>132,'cname'=>'连云港','pid'=>10],
['cid'=>133,'cname'=>'淮安','pid'=>10],
['cid'=>134,'cname'=>'盐城','pid'=>10],
['cid'=>135,'cname'=>'扬州','pid'=>10],
['cid'=>136,'cname'=>'镇江','pid'=>10],
['cid'=>137,'cname'=>'泰州','pid'=>10],
['cid'=>138,'cname'=>'宿迁','pid'=>10],
['cid'=>139,'cname'=>'杭州','pid'=>11],
['cid'=>140,'cname'=>'宁波','pid'=>11],
['cid'=>141,'cname'=>'温州','pid'=>11],
['cid'=>142,'cname'=>'嘉兴','pid'=>11],
['cid'=>143,'cname'=>'湖州','pid'=>11],
['cid'=>144,'cname'=>'绍兴','pid'=>11],
['cid'=>145,'cname'=>'金华','pid'=>11],
['cid'=>146,'cname'=>'衢州','pid'=>11],
['cid'=>147,'cname'=>'舟山','pid'=>11],
['cid'=>148,'cname'=>'台州','pid'=>11],
['cid'=>149,'cname'=>'丽水','pid'=>11],
['cid'=>150,'cname'=>'合肥','pid'=>12],
['cid'=>151,'cname'=>'芜湖','pid'=>12],
['cid'=>152,'cname'=>'蚌埠','pid'=>12],
['cid'=>153,'cname'=>'淮南','pid'=>12],
['cid'=>154,'cname'=>'马鞍山','pid'=>12],
['cid'=>155,'cname'=>'淮北','pid'=>12],
['cid'=>156,'cname'=>'铜陵','pid'=>12],
['cid'=>157,'cname'=>'安庆','pid'=>12],
['cid'=>158,'cname'=>'黄山','pid'=>12],
['cid'=>159,'cname'=>'滁州','pid'=>12],
['cid'=>160,'cname'=>'阜阳','pid'=>12],
['cid'=>161,'cname'=>'宿州','pid'=>12],
['cid'=>162,'cname'=>'巢湖','pid'=>12],
['cid'=>163,'cname'=>'六安','pid'=>12],
['cid'=>164,'cname'=>'亳州','pid'=>12],
['cid'=>165,'cname'=>'池州','pid'=>12],
['cid'=>166,'cname'=>'宣城','pid'=>12],
['cid'=>167,'cname'=>'福州','pid'=>13],
['cid'=>168,'cname'=>'厦门','pid'=>13],
['cid'=>169,'cname'=>'莆田','pid'=>13],
['cid'=>170,'cname'=>'三明','pid'=>13],
['cid'=>171,'cname'=>'泉州','pid'=>13],
['cid'=>172,'cname'=>'漳州','pid'=>13],
['cid'=>173,'cname'=>'南平','pid'=>13],
['cid'=>174,'cname'=>'龙岩','pid'=>13],
['cid'=>175,'cname'=>'宁德','pid'=>13],
['cid'=>176,'cname'=>'南昌','pid'=>14],
['cid'=>177,'cname'=>'景德镇','pid'=>14],
['cid'=>178,'cname'=>'萍乡','pid'=>14],
['cid'=>179,'cname'=>'九江','pid'=>14],
['cid'=>180,'cname'=>'新余','pid'=>14],
['cid'=>181,'cname'=>'鹰潭','pid'=>14],
['cid'=>182,'cname'=>'赣州','pid'=>14],
['cid'=>183,'cname'=>'吉安','pid'=>14],
['cid'=>184,'cname'=>'宜春','pid'=>14],
['cid'=>185,'cname'=>'抚州','pid'=>14],
['cid'=>186,'cname'=>'上饶','pid'=>14],
['cid'=>187,'cname'=>'济南','pid'=>15],
['cid'=>188,'cname'=>'青岛','pid'=>15],
['cid'=>189,'cname'=>'淄博','pid'=>15],
['cid'=>190,'cname'=>'枣庄','pid'=>15],
['cid'=>191,'cname'=>'东营','pid'=>15],
['cid'=>192,'cname'=>'烟台','pid'=>15],
['cid'=>193,'cname'=>'潍坊','pid'=>15],
['cid'=>194,'cname'=>'济宁','pid'=>15],
['cid'=>195,'cname'=>'泰安','pid'=>15],
['cid'=>196,'cname'=>'威海','pid'=>15],
['cid'=>197,'cname'=>'日照','pid'=>15],
['cid'=>198,'cname'=>'莱芜','pid'=>15],
['cid'=>199,'cname'=>'临沂','pid'=>15],
['cid'=>200,'cname'=>'德州','pid'=>15],
['cid'=>201,'cname'=>'聊城','pid'=>15],
['cid'=>202,'cname'=>'滨州','pid'=>15],
['cid'=>203,'cname'=>'荷泽','pid'=>15],
['cid'=>204,'cname'=>'郑州','pid'=>16],
['cid'=>205,'cname'=>'开封','pid'=>16],
['cid'=>206,'cname'=>'洛阳','pid'=>16],
['cid'=>207,'cname'=>'平顶山','pid'=>16],
['cid'=>208,'cname'=>'安阳','pid'=>16],
['cid'=>209,'cname'=>'鹤壁','pid'=>16],
['cid'=>210,'cname'=>'新乡','pid'=>16],
['cid'=>211,'cname'=>'焦作','pid'=>16],
['cid'=>212,'cname'=>'濮阳','pid'=>16],
['cid'=>213,'cname'=>'许昌','pid'=>16],
['cid'=>214,'cname'=>'漯河','pid'=>16],
['cid'=>215,'cname'=>'三门峡','pid'=>16],
['cid'=>216,'cname'=>'南阳','pid'=>16],
['cid'=>217,'cname'=>'商丘','pid'=>16],
['cid'=>218,'cname'=>'信阳','pid'=>16],
['cid'=>219,'cname'=>'周口','pid'=>16],
['cid'=>220,'cname'=>'驻马店','pid'=>16],
['cid'=>221,'cname'=>'武汉','pid'=>17],
['cid'=>222,'cname'=>'黄石','pid'=>17],
['cid'=>223,'cname'=>'十堰','pid'=>17],
['cid'=>224,'cname'=>'宜昌','pid'=>17],
['cid'=>225,'cname'=>'襄樊','pid'=>17],
['cid'=>226,'cname'=>'鄂州','pid'=>17],
['cid'=>227,'cname'=>'荆门','pid'=>17],
['cid'=>228,'cname'=>'孝感','pid'=>17],
['cid'=>229,'cname'=>'荆州','pid'=>17],
['cid'=>230,'cname'=>'黄冈','pid'=>17],
['cid'=>231,'cname'=>'咸宁','pid'=>17],
['cid'=>232,'cname'=>'随州','pid'=>17],
['cid'=>233,'cname'=>'恩施','pid'=>17],
['cid'=>234,'cname'=>'神农架','pid'=>17],
['cid'=>235,'cname'=>'长沙','pid'=>18],
['cid'=>236,'cname'=>'株洲','pid'=>18],
['cid'=>237,'cname'=>'湘潭','pid'=>18],
['cid'=>238,'cname'=>'衡阳','pid'=>18],
['cid'=>239,'cname'=>'邵阳','pid'=>18],
['cid'=>240,'cname'=>'岳阳','pid'=>18],
['cid'=>241,'cname'=>'常德','pid'=>18],
['cid'=>242,'cname'=>'张家界','pid'=>18],
['cid'=>243,'cname'=>'益阳','pid'=>18],
['cid'=>244,'cname'=>'郴州','pid'=>18],
['cid'=>245,'cname'=>'永州','pid'=>18],
['cid'=>246,'cname'=>'怀化','pid'=>18],
['cid'=>247,'cname'=>'娄底','pid'=>18],
['cid'=>248,'cname'=>'湘西','pid'=>18],
['cid'=>249,'cname'=>'广州','pid'=>19],
['cid'=>250,'cname'=>'韶关','pid'=>19],
['cid'=>251,'cname'=>'深圳','pid'=>19],
['cid'=>252,'cname'=>'珠海','pid'=>19],
['cid'=>253,'cname'=>'汕头','pid'=>19],
['cid'=>254,'cname'=>'佛山','pid'=>19],
['cid'=>255,'cname'=>'江门','pid'=>19],
['cid'=>256,'cname'=>'湛江','pid'=>19],
['cid'=>257,'cname'=>'茂名','pid'=>19],
['cid'=>258,'cname'=>'肇庆','pid'=>19],
['cid'=>259,'cname'=>'惠州','pid'=>19],
['cid'=>260,'cname'=>'梅州','pid'=>19],
['cid'=>261,'cname'=>'汕尾','pid'=>19],
['cid'=>262,'cname'=>'河源','pid'=>19],
['cid'=>263,'cname'=>'阳江','pid'=>19],
['cid'=>264,'cname'=>'清远','pid'=>19],
['cid'=>265,'cname'=>'东莞','pid'=>19],
['cid'=>266,'cname'=>'中山','pid'=>19],
['cid'=>267,'cname'=>'潮州','pid'=>19],
['cid'=>268,'cname'=>'揭阳','pid'=>19],
['cid'=>269,'cname'=>'云浮','pid'=>19],
['cid'=>270,'cname'=>'南宁','pid'=>20],
['cid'=>271,'cname'=>'柳州','pid'=>20],
['cid'=>272,'cname'=>'桂林','pid'=>20],
['cid'=>273,'cname'=>'梧州','pid'=>20],
['cid'=>274,'cname'=>'北海','pid'=>20],
['cid'=>275,'cname'=>'防城港','pid'=>20],
['cid'=>276,'cname'=>'钦州','pid'=>20],
['cid'=>277,'cname'=>'贵港','pid'=>20],
['cid'=>278,'cname'=>'玉林','pid'=>20],
['cid'=>279,'cname'=>'百色','pid'=>20],
['cid'=>280,'cname'=>'贺州','pid'=>20],
['cid'=>281,'cname'=>'河池','pid'=>20],
['cid'=>282,'cname'=>'来宾','pid'=>20],
['cid'=>283,'cname'=>'崇左','pid'=>20],
['cid'=>284,'cname'=>'海口','pid'=>21],
['cid'=>285,'cname'=>'三亚','pid'=>21],
['cid'=>286,'cname'=>'重庆','pid'=>22],
['cid'=>287,'cname'=>'万州区','pid'=>22],
['cid'=>288,'cname'=>'涪陵区','pid'=>22],
['cid'=>289,'cname'=>'渝中区','pid'=>22],
['cid'=>290,'cname'=>'大渡口区','pid'=>22],
['cid'=>291,'cname'=>'江北区','pid'=>22],
['cid'=>292,'cname'=>'沙坪坝区','pid'=>22],
['cid'=>293,'cname'=>'九龙坡区','pid'=>22],
['cid'=>294,'cname'=>'南岸区','pid'=>22],
['cid'=>295,'cname'=>'北碚区','pid'=>22],
['cid'=>296,'cname'=>'万盛区','pid'=>22],
['cid'=>297,'cname'=>'双桥区','pid'=>22],
['cid'=>298,'cname'=>'渝北区','pid'=>22],
['cid'=>299,'cname'=>'巴南区','pid'=>22],
['cid'=>300,'cname'=>'黔江区','pid'=>22],
['cid'=>301,'cname'=>'长寿区','pid'=>22],
['cid'=>302,'cname'=>'綦江县','pid'=>22],
['cid'=>303,'cname'=>'潼南县','pid'=>22],
['cid'=>304,'cname'=>'铜梁县','pid'=>22],
['cid'=>305,'cname'=>'大足县','pid'=>22],
['cid'=>306,'cname'=>'荣昌县','pid'=>22],
['cid'=>307,'cname'=>'璧山县','pid'=>22],
['cid'=>308,'cname'=>'梁平县','pid'=>22],
['cid'=>309,'cname'=>'城口县','pid'=>22],
['cid'=>310,'cname'=>'丰都县','pid'=>22],
['cid'=>311,'cname'=>'垫江县','pid'=>22],
['cid'=>312,'cname'=>'武隆县','pid'=>22],
['cid'=>313,'cname'=>'忠县','pid'=>22],
['cid'=>314,'cname'=>'开县','pid'=>22],
['cid'=>315,'cname'=>'云阳县','pid'=>22],
['cid'=>316,'cname'=>'奉节县','pid'=>22],
['cid'=>317,'cname'=>'巫山县','pid'=>22],
['cid'=>318,'cname'=>'巫溪县','pid'=>22],
['cid'=> 319,'石柱土家族自治县','pid'=>22],
['cid'=> 320,'cname'=>'秀山土家族苗族自治县','pid'=>22],
['cid'=> 321,'cname'=>'酉阳土家族苗族自治县','pid'=>22],
['cid'=> 322,'cname'=>'彭水苗族土家族自治县','pid'=>22],
['cid'=>323,'cname'=>'江津','pid'=>22],
['cid'=>324,'cname'=>'合川','pid'=>22],
['cid'=>325,'cname'=>'永川','pid'=>22],
['cid'=>326,'cname'=>'南川','pid'=>22],
['cid'=>327,'cname'=>'成都','pid'=>23],
['cid'=>328,'cname'=>'自贡','pid'=>23],
['cid'=>329,'cname'=>'攀枝花','pid'=>23],
['cid'=>330,'cname'=>'泸州','pid'=>23],
['cid'=>331,'cname'=>'德阳','pid'=>23],
['cid'=>332,'cname'=>'绵阳','pid'=>23],
['cid'=>333,'cname'=>'广元','pid'=>23],
['cid'=>334,'cname'=>'遂宁','pid'=>23],
['cid'=>335,'cname'=>'内江','pid'=>23],
['cid'=>336,'cname'=>'乐山','pid'=>23],
['cid'=>337,'cname'=>'南充','pid'=>23],
['cid'=>338,'cname'=>'眉山','pid'=>23],
['cid'=>339,'cname'=>'宜宾','pid'=>23],
['cid'=>340,'cname'=>'广安','pid'=>23],
['cid'=>341,'cname'=>'达州','pid'=>23],
['cid'=>342,'cname'=>'雅安','pid'=>23],
['cid'=>343,'cname'=>'巴中','pid'=>23],
['cid'=>344,'cname'=>'资阳','pid'=>23],
['cid'=>345,'cname'=>'阿坝','pid'=>23],
['cid'=>346,'cname'=>'甘孜','pid'=>23],
['cid'=>347,'cname'=>'凉山','pid'=>23],
['cid'=>348,'cname'=>'贵阳','pid'=>24],
['cid'=>349,'cname'=>'六盘水','pid'=>24],
['cid'=>350,'cname'=>'遵义','pid'=>24],
['cid'=>351,'cname'=>'安顺','pid'=>24],
['cid'=>352,'cname'=>'铜仁','pid'=>24],
['cid'=>353,'cname'=>'黔西南','pid'=>24],
['cid'=>354,'cname'=>'毕节','pid'=>24],
['cid'=>355,'cname'=>'黔东南','pid'=>24],
['cid'=>356,'cname'=>'黔南','pid'=>24],
['cid'=>357,'cname'=>'昆明','pid'=>25],
['cid'=>358,'cname'=>'曲靖','pid'=>25],
['cid'=>359,'cname'=>'玉溪','pid'=>25],
['cid'=>360,'cname'=>'保山','pid'=>25],
['cid'=>361,'cname'=>'昭通','pid'=>25],
['cid'=>362,'cname'=>'丽江','pid'=>25],
['cid'=>363,'cname'=>'思茅','pid'=>25],
['cid'=>364,'cname'=>'临沧','pid'=>25],
['cid'=>365,'cname'=>'楚雄','pid'=>25],
['cid'=>366,'cname'=>'红河','pid'=>25],
['cid'=>367,'cname'=>'文山','pid'=>25],
['cid'=>368,'cname'=>'西双版纳','pid'=>25],
['cid'=>369,'cname'=>'大理','pid'=>25],
['cid'=>370,'cname'=>'德宏','pid'=>25],
['cid'=>371,'cname'=>'怒江','pid'=>25],
['cid'=>372,'cname'=>'迪庆','pid'=>25],
['cid'=>373,'cname'=>'拉萨','pid'=>26],
['cid'=>374,'cname'=>'昌都','pid'=>26],
['cid'=>375,'cname'=>'山南','pid'=>26],
['cid'=>376,'cname'=>'日喀则','pid'=>26],
['cid'=>377,'cname'=>'那曲','pid'=>26],
['cid'=>378,'cname'=>'阿里','pid'=>26],
['cid'=>379,'cname'=>'林芝','pid'=>26],
['cid'=>380,'cname'=>'西安','pid'=>27],
['cid'=>381,'cname'=>'铜川','pid'=>27],
['cid'=>382,'cname'=>'宝鸡','pid'=>27],
['cid'=>383,'cname'=>'咸阳','pid'=>27],
['cid'=>384,'cname'=>'渭南','pid'=>27],
['cid'=>385,'cname'=>'延安','pid'=>27],
['cid'=>386,'cname'=>'汉中','pid'=>27],
['cid'=>387,'cname'=>'榆林','pid'=>27],
['cid'=>388,'cname'=>'安康','pid'=>27],
['cid'=>389,'cname'=>'商洛','pid'=>27],
['cid'=>390,'cname'=>'兰州','pid'=>28],
['cid'=>391,'cname'=>'嘉峪关','pid'=>28],
['cid'=>392,'cname'=>'金昌','pid'=>28],
['cid'=>393,'cname'=>'白银','pid'=>28],
['cid'=>394,'cname'=>'天水','pid'=>28],
['cid'=>395,'cname'=>'武威','pid'=>28],
['cid'=>396,'cname'=>'张掖','pid'=>28],
['cid'=>397,'cname'=>'平凉','pid'=>28],
['cid'=>398,'cname'=>'酒泉','pid'=>28],
['cid'=>399,'cname'=>'庆阳','pid'=>28],
['cid'=>400,'cname'=>'定西','pid'=>28],
['cid'=>401,'cname'=>'陇南','pid'=>28],
['cid'=>402,'cname'=>'临夏','pid'=>28],
['cid'=>403,'cname'=>'甘南','pid'=>28],
['cid'=>404,'cname'=>'西宁','pid'=>29],
['cid'=>405,'cname'=>'海东','pid'=>29],
['cid'=>406,'cname'=>'海北','pid'=>29],
['cid'=>407,'cname'=>'黄南','pid'=>29],
['cid'=>408,'cname'=>'海南','pid'=>29],
['cid'=>409,'cname'=>'果洛','pid'=>29],
['cid'=>410,'cname'=>'玉树','pid'=>29],
['cid'=>411,'cname'=>'海西','pid'=>29],
['cid'=>412,'cname'=>'银川','pid'=>30],
['cid'=>413,'cname'=>'石嘴山','pid'=>30],
['cid'=>414,'cname'=>'吴忠','pid'=>30],
['cid'=>415,'cname'=>'固原','pid'=>30],
['cid'=>416,'cname'=>'中卫','pid'=>30],
['cid'=>417,'cname'=>'乌鲁木齐','pid'=>31],
['cid'=>418,'cname'=>'克拉玛依','pid'=>31],
['cid'=>419,'cname'=>'吐鲁番','pid'=>31],
['cid'=>420,'cname'=>'哈密','pid'=>31],
['cid'=>421,'cname'=>'昌吉','pid'=>31],
['cid'=>422,'cname'=>'博尔塔拉','pid'=>31],
['cid'=>423,'cname'=>'巴音郭楞','pid'=>31],
['cid'=>424,'cname'=>'阿克苏','pid'=>31],
['cid'=>425,'cname'=>'克孜勒苏','pid'=>31],
['cid'=>426,'cname'=>'喀什','pid'=>31],
['cid'=>427,'cname'=>'和田','pid'=>31],
['cid'=>428,'cname'=>'伊犁','pid'=>31],
['cid'=>429,'cname'=>'塔城','pid'=>31],
['cid'=>430,'cname'=>'阿勒泰','pid'=>31],
['cid'=>431,'cname'=>'石河子','pid'=>31],
['cid'=>432,'cname'=>'阿拉尔','pid'=>31],
['cid'=>433,'cname'=>'图木舒克','pid'=>31],
['cid'=>434,'cname'=>'五家渠','pid'=>31],
['cid'=>435,'cname'=>'***','pid'=>32],
['cid'=>436,'cname'=>'澳门','pid'=>33],
['cid'=>437,'cname'=>'台湾','pid'=>34]
];
isset($_POST['pid']) ? $_POST['pid'] : 0;
$pid = $_POST['pid'];
$pidArr = [];
foreach($city as $k=>$v){
if($v['pid'] == $pid){
$pidArr[] = $v;
}
}
echo json_encode($pidArr);
?>
//province代码
<?php
$province = [
['pid'=>1, 'pname'=>'北京'],
['pid'=>2, 'pname'=>'天津'],
['pid'=>3, 'pname'=>'河北'],
['pid'=>4, 'pname'=>'山西'],
['pid'=>5, 'pname'=>'内蒙古'],
['pid'=>6, 'pname'=>'辽宁'],
['pid'=>7, 'pname'=>'吉林'],
['pid'=>8, 'pname'=>'黑龙江'],
['pid'=>9, 'pname'=>'上海'],
['pid'=>10, 'pname'=>'江苏'],
['pid'=>11, 'pname'=>'浙江'],
['pid'=>12, 'pname'=>'安徽'],
['pid'=>13, 'pname'=>'福建'],
['pid'=>14, 'pname'=>'江西'],
['pid'=>15, 'pname'=>'山东'],
['pid'=>16, 'pname'=>'河南'],
['pid'=>17, 'pname'=>'湖北'],
['pid'=>18, 'pname'=>'湖南'],
['pid'=>19, 'pname'=>'广东'],
['pid'=>20, 'pname'=>'广西'],
['pid'=>21, 'pname'=>'海南'],
['pid'=>22, 'pname'=>'重庆'],
['pid'=>23, 'pname'=>'四川'],
['pid'=>24, 'pname'=>'贵州'],
['pid'=>25, 'pname'=>'云南'],
['pid'=>26, 'pname'=>'西藏'],
['pid'=>27, 'pname'=>'陕西'],
['pid'=>28, 'pname'=>'甘肃'],
['pid'=>29, 'pname'=>'青海'],
['pid'=>30, 'pname'=>'宁夏'],
['pid'=>31, 'pname'=>'新疆'],
['pid'=>32, 'pname'=>'***'],
['pid'=>33, 'pname'=>'澳门'],
['pid'=>34, 'pname'=>'台湾']
];
echo json_encode($province);
?>