js怎么获取php的数组
php中存在省市对应数组
$info = array(
'北京'=>array('北京市'),
'福建'=>array("福州市","龙岩市","南平市","宁德市","莆田市","泉州市","三明市","厦门市","漳州市"),
'甘肃'=>array("白银市","定西市","甘南藏族自治州","嘉峪关","金昌市","酒泉市","兰州市","临夏回族自治州","陇南市","平凉市","庆阳市","天水市","武威市","张掖市"),
'广东'=>array("潮州市","东莞市","佛山市","广州市","河源市","惠州市","江门市","揭阳市","茂名市","梅州市","清远市","汕头市","汕尾市","韶关市","深圳市","阳江市","云浮市","湛江市","肇庆市","中山市","珠海市"),);
怎么在前端js或者这个数组
------解决方案--------------------
转化成json格式
echo json_encode($info);
不知道你这是ajax还是? 如果不是,那就输出一段Js 代码好了
<script><br />var jsondata = <?php echo json_encode($info); ?>;<br /></script>
如果是ajax ,那么JQuery的ajax json函数很好用。或者用eval("'(" + ajaxjsondata + ")'");什么的也很方便
------解决方案--------------------
$arr = "[[1,2,3],[2,3,4]]"; echo $arr; ?> <script> var tmp = '<?=$arr?>'; tmp = eval('('+tmp+')') alert(tmp.length) </script> <div class="clear"> </div>