首頁 >後端開發 >php教程 >js如何获取php的数组

js如何获取php的数组

WBOY
WBOY原創
2016-06-13 10:17:351085瀏覽

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 + ")'");什么的也很方便
------解决方案--------------------

HTML code
    $arr = "[[1,2,3],[2,3,4]]";    echo $arr;?><script>    var tmp = '<?=$arr?>';    tmp = eval('('+tmp+')')    alert(tmp.length)</script><div class="clear">
                 
              
              
        
            </div>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn