国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

PHP數組轉換為js數組

cyrils / 1713人閱讀

摘要:背景當我們用分層到時候,有時候需要初始化一些變量,并至的模版中,其中有一些是這種引擎解析的變量,有時候也需要來一發解析的數組變量,以下例子就是簡單拼接。

背景:

當我們用mvc分層到時候,有時候需要初始化一些變量,并assign 至view的模版中,其中有一些是smarty這種引擎解析的php變量,有時候也需要來一發js解析的數組變量,以下例子就是簡單拼接。

代碼

  array (
    0 => "安徽-ah",
    101 => "合肥-hf",
    102 => "安慶-aq",
    103 => "蚌埠-bb",
    104 => "巢湖-ch",
    105 => "池州-cz",
    106 => "阜陽-fy",
    107 => "淮北-hb",
    108 => "淮南-hn",
    109 => "六安-la",
    110 => "馬鞍山-mas",
    112 => "寧國-ng",
    113 => "銅陵-tl",
    114 => "蕪湖-wh",
    115 => "宣城-xc",
    116 => "滁州-cz",
    117 => "亳州-bz",
    118 => "黃山-hs",
    120 => "宿州-sz",
    121 => "桐城-tc",
  ),
  2 =>
  array (
    0 => "北京-bj",
    201 => "北京-bj",
  ),
  3 =>
  array (
    0 => "福建-fj",
    301 => "福州-fz",
    302 => "廈門-xm",
    303 => "龍巖-ly",
    305 => "漳州-zz",
    306 => "莆田-pt",
    307 => "泉州-qz",
    309 => "武夷山-wys",
    314 => "南平-np",
    315 => "寧德-nd",
    318 => "三明-sm",
  ),
  4 =>
  array (
    0 => "甘肅-gs",
    401 => "蘭州-lz",
    402 => "定西-dx",
    405 => "平涼-pl",
    407 => "臨夏-lx",
    409 => "酒泉-jq",
    410 => "張掖-zy",
    411 => "慶陽-qy",
    412 => "武威-ww",
    415 => "天水-ts",
    416 => "白銀-by",
    3113 => "金昌-jc",
  ),
  5 =>
  array (
    0 => "廣東-gd",
    501 => "廣州-gz",
    502 => "深圳-sz",
    503 => "珠海-zh",
    504 => "東莞-dg",
    505 => "中山-zs",
    507 => "汕頭-st",
    510 => "潮州-cz",
    511 => "韶關-sg",
    513 => "湛江-zj",
    514 => "肇慶-zq",
    515 => "茂名-mm",
    516 => "梅州-mz",
    518 => "佛山-fs",
    520 => "惠州-hz",
    521 => "江門-jm",
    522 => "揭陽-jy",
    524 => "清遠-qy",
    528 => "云浮-yf",
    532 => "陽江-yj",
    535 => "河源-hy",
    550 => "汕尾-sw",
    1012 => "揭東-jd",
    8110 => "順德-sd",
  ),
  6 =>
  array (
    0 => "廣西-gx",
    601 => "南寧-nn",
    602 => "柳州-lz",
    603 => "桂林-gl",
    604 => "北海-bh",
    605 => "百色-bs",
    608 => "貴港-gg",
    610 => "玉林-yl",
    612 => "欽州-qz",
    613 => "梧州-wz",
    618 => "防城港-fcg",
  ),
  7 =>
  array (
    0 => "貴州-gz",
    701 => "貴陽-gy",
    702 => "遵義-zy",
    703 => "興義-xy",
    705 => "安順-as",
    706 => "畢節-bj",
    707 => "都勻-dy",
    708 => "六盤水-lps",
    709 => "凱里-kl",
    710 => "銅仁-tr",
  ),
  8 =>
  array (
    0 => "海南-hn",
    801 => "海口-hk",
    803 => "三亞-sy",
    8101 => "儋州-dz",
  ),
  9 =>
  array (
    0 => "河北-hb",
    901 => "石家莊-sjz",
    902 => "唐山-ts",
    903 => "邢臺-xt",
    905 => "秦皇島-qhd",
    906 => "廊坊-lf",
    907 => "邯鄲-hd",
    908 => "衡水-hs",
    909 => "滄州-cz",
    910 => "保定-bd",
    911 => "張家口-zjk",
    912 => "承德-cd",
    3112 => "三河-sh",
  ),
  10 =>
  array (
    0 => "河南-hn",
    1001 => "鄭州-zz",
    1002 => "洛陽-ly",
    1004 => "信陽-xy",
    1005 => "新鄉-xx",
    1006 => "商丘-sq",
    1007 => "三門峽-smx",
    1008 => "濮陽-py",
    1009 => "南陽-ny",
    1011 => "焦作-jz",
    1013 => "開封-kf",
    1014 => "安陽-ay",
    1016 => "鶴壁-hb",
    1018 => "平頂山-pds",
    1019 => "濟源-jy",
    1021 => "駐馬店-zmd",
  ),
  21 =>
  array (
    0 => "山東-sd",
    1015 => "德州-dz",
    2101 => "濟南-jn",
    2102 => "青島-qd",
    2103 => "煙臺-yt",
    2104 => "威海-wh",
    2105 => "濰坊-wf",
    2106 => "泰安-ta",
    2107 => "棗莊-zz",
    2109 => "淄博-zb",
    2110 => "東營-dy",
    2111 => "高密-gm",
    2112 => "菏澤-hz",
    2113 => "濱州-bz",
    2114 => "聊城-lc",
    2117 => "臨沂-ly",
    2118 => "濟寧-jn",
    2120 => "日照-rz",
  ),
  11 =>
  array (
    0 => "黑龍江-hlj",
    1101 => "哈爾濱-heb",
    1102 => "大慶-dq",
    1103 => "齊齊哈爾-qqhe",
    1104 => "鶴崗-hg",
    1106 => "佳木斯-jms",
    1107 => "雞西-jx",
    1108 => "牡丹江-mdj",
    1112 => "伊春-yc",
    1116 => "綏化-sh",
    1118 => "雙鴨山-sys",
  )
);
 function get_provice_city_js($arrData=[],$jsVarName=""){

  $js_result="";
  $intCount=0;
   foreach($arrData as $intProv => $arrAreaData)
                {
                    $js_result .= $jsVarName."[".$intCount++."] = new Array("".$intProv."-".$arrAreaData[0].""";

                    //再循環省下面的城市
                    foreach($arrAreaData as $intCity => $strCity)
                    {

                      //如果是省份,忽略
                        if ($intCity == 0) {
                            continue;
                        }

                        $js_result .= ","".$intCity."-".$strCity.""";
                    }
                    $js_result .= ");"."
";
                }
                return $js_result;

}

echo get_provice_city_js($php_array,"myProject.");
輸出
myProject.[0] = new Array("1-安徽-ah","101-合肥-hf","102-安慶-aq","103-蚌埠-bb","104-巢湖-ch","105-池州-cz","106-阜陽-fy","107-淮北-hb","108-淮南-hn","109-六安-la","110-馬鞍山-mas","112-寧國-ng","113-銅陵-tl","114-蕪湖-wh","115-宣城-xc","116-滁州-cz","117-亳州-bz","118-黃山-hs","120-宿州-sz","121-桐城-tc");
myProject.[1] = new Array("2-北京-bj","201-北京-bj");
myProject.[2] = new Array("3-福建-fj","301-福州-fz","302-廈門-xm","303-龍巖-ly","305-漳州-zz","306-莆田-pt","307-泉州-qz","309-武夷山-wys","314-南平-np","315-寧德-nd","318-三明-sm");
myProject.[3] = new Array("4-甘肅-gs","401-蘭州-lz","402-定西-dx","405-平涼-pl","407-臨夏-lx","409-酒泉-jq","410-張掖-zy","411-慶陽-qy","412-武威-ww","415-天水-ts","416-白銀-by","3113-金昌-jc");
myProject.[4] = new Array("5-廣東-gd","501-廣州-gz","502-深圳-sz","503-珠海-zh","504-東莞-dg","505-中山-zs","507-汕頭-st","510-潮州-cz","511-韶關-sg","513-湛江-zj","514-肇慶-zq","515-茂名-mm","516-梅州-mz","518-佛山-fs","520-惠州-hz","521-江門-jm","522-揭陽-jy","524-清遠-qy","528-云浮-yf","532-陽江-yj","535-河源-hy","550-汕尾-sw","1012-揭東-jd","8110-順德-sd");
myProject.[5] = new Array("6-廣西-gx","601-南寧-nn","602-柳州-lz","603-桂林-gl","604-北海-bh","605-百色-bs","608-貴港-gg","610-玉林-yl","612-欽州-qz","613-梧州-wz","618-防城港-fcg");
myProject.[6] = new Array("7-貴州-gz","701-貴陽-gy","702-遵義-zy","703-興義-xy","705-安順-as","706-畢節-bj","707-都勻-dy","708-六盤水-lps","709-凱里-kl","710-銅仁-tr");
myProject.[7] = new Array("8-海南-hn","801-海口-hk","803-三亞-sy","8101-儋州-dz");
myProject.[8] = new Array("9-河北-hb","901-石家莊-sjz","902-唐山-ts","903-邢臺-xt","905-秦皇島-qhd","906-廊坊-lf","907-邯鄲-hd","908-衡水-hs","909-滄州-cz","910-保定-bd","911-張家口-zjk","912-承德-cd","3112-三河-sh");
myProject.[9] = new Array("10-河南-hn","1001-鄭州-zz","1002-洛陽-ly","1004-信陽-xy","1005-新鄉-xx","1006-商丘-sq","1007-三門峽-smx","1008-濮陽-py","1009-南陽-ny","1011-焦作-jz","1013-開封-kf","1014-安陽-ay","1016-鶴壁-hb","1018-平頂山-pds","1019-濟源-jy","1021-駐馬店-zmd");
myProject.[10] = new Array("21-山東-sd","1015-德州-dz","2101-濟南-jn","2102-青島-qd","2103-煙臺-yt","2104-威海-wh","2105-濰坊-wf","2106-泰安-ta","2107-棗莊-zz","2109-淄博-zb","2110-東營-dy","2111-高密-gm","2112-菏澤-hz","2113-濱州-bz","2114-聊城-lc","2117-臨沂-ly","2118-濟寧-jn","2120-日照-rz");
myProject.[11] = new Array("11-黑龍江-hlj","1101-哈爾濱-heb","1102-大慶-dq","1103-齊齊哈爾-qqhe","1104-鶴崗-hg","1106-佳木斯-jms","1107-雞西-jx","1108-牡丹江-mdj","1112-伊春-yc","1116-綏化-sh","1118-雙鴨山-sys");
[Finished in 0.1s]

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/30675.html

相關文章

  • PHP數組轉換js數組

    摘要:背景當我們用分層到時候,有時候需要初始化一些變量,并至的模版中,其中有一些是這種引擎解析的變量,有時候也需要來一發解析的數組變量,以下例子就是簡單拼接。 背景: 當我們用mvc分層到時候,有時候需要初始化一些變量,并assign 至view的模版中,其中有一些是smarty這種引擎解析的php變量,有時候也需要來一發js解析的數組變量,以下例子就是簡單拼接。 代碼

    dingding199389 評論0 收藏0
  • PHPJS數組轉換

    因為程序用到,之前又沒寫過,費了很大的勁才寫出來。 主要是編輯文章部分,讀取,修改關鍵詞 發布文章部分 //定義JS的數組 var tagslist = []; //然后把用戶輸入的標簽添加到這個數組里 tagslist.push(測試1); //發送到后臺的時候進行了編碼,ECMAScript v3 反對使用escape,所以盡量不用了 encodeURI(tagslist) //后臺接...

    scq000 評論0 收藏0
  • PHPJS數組轉換

    因為程序用到,之前又沒寫過,費了很大的勁才寫出來。 主要是編輯文章部分,讀取,修改關鍵詞 發布文章部分 //定義JS的數組 var tagslist = []; //然后把用戶輸入的標簽添加到這個數組里 tagslist.push(測試1); //發送到后臺的時候進行了編碼,ECMAScript v3 反對使用escape,所以盡量不用了 encodeURI(tagslist) //后臺接...

    kycool 評論0 收藏0
  • 前端知識點總結——AJAX

    摘要:對象的語法對象名屬性值屬性值屬性值屬性值林黛玉這個對象所對應的屬性如下林黛玉如果對象取值的時候,直接對象屬性名稱就可以林黛玉什么是對象表現方式對象表示法,即以對象的格式表現出來的字符串。 前端知識點總結——Ajax 1.ajax 1.URL的作用 用于表示任意一個資源的位置(互聯網上) 2.詳解 格式: ://:@:/;?# scheme:方案協議,以哪種方式到服務獲...

    hzc 評論0 收藏0

發表評論

0條評論

最新活動
閱讀需要支付1元查看
<