• PHP中获取我的城市列表,通过排序,通过AZ的循环!数列出相同的首字母结果!,放到一个以AZ为key的数组里面去,再返回我要的结果!


     1 $city = Array
    2 (
    3 Array
    4 (
    5 'city_id' => "1",
    6 'city_name' => "全国",
    7 'ename' => "QuanGuo",
    8 'letter' => "Q",
    9 'city_content' => "ADSFADSFA",
    10 'order_desc' => "1",
    11 'display' => "1",
    12 'short_description' => "ADSFADF",
    13 'keyword' => 'AF,ASDF,ADF',
    14 'create_name' =>"",
    15 'create_time' => ""
    16 ),
    17 Array
    18 (
    19 'city_id' => "9",
    20 'city_name' => "台州",
    21 'ename' => "TaiZhou",
    22 'letter' => "T",
    23 'city_content' => "AAAA",
    24 'order_desc' => "AAA",
    25 'display' => "1",
    26 'short_description' => "AAA",
    27 'keyword' => "AAA",
    28 'create_name' => "xiaozi",
    29 'create_time' => "1310525878"
    30 ),
    31 Array
    32 (
    33 'city_id' => "10",
    34 'city_name' => "杭州",
    35 'ename' => "hangzhou",
    36 'letter' => "H",
    37 'city_content' => "asdf",
    38 'order_desc' => "2",
    39 'display' => "1",
    40 'short_description' => "sdfa",
    41 'keyword' => "s",
    42 'create_name' => "xiaozi",
    43 'create_time' => "1310526071"
    44 ),
    45 Array
    46 (
    47 'city_id' => "11",
    48 'city_name' => "ASDFASDFADSF",
    49 'ename' => "ASDFASDFASDF",
    50 'letter' => "T",
    51 'city_content' => "222ss",
    52 'order_desc' => "22",
    53 'display' => "1",
    54 'short_description' => "22",
    55 'keyword' => "ss",
    56 'create_name' => "zongzi",
    57 'create_time' => "1310701443"
    58 )
    59 )

     //处理上面的数组 

    //获取所有城市,整排        
    static public function get_all_city($city)
    {
    if (is_array($city))
    {
    for ($i=A;$i<=Z;$i++)
    {
    foreach ($city as $k=>$vo)
    {
    if ($i == $vo['letter'])
    {
    $array[$i][$k] = $vo;
    }
    }

    if($i == Z)
    {
    break;
    }
    }
    }
    return $array;
    }

     $city = get_all_city($city);

    Array
    (
        [H] => Array
            (
                [2] => Array
                    (
                        [city_id] => 10
                        [city_name] => 杭州
                        [ename] => hangzhou
                        [letter] => H
                        [city_content] => asdf
                        [order_desc] => 2
                        [display] => 1
                        [short_description] => sdfa
                        [keyword] => s
                        [create_name] => xiaozi
                        [create_time] => 1310526071
                    )
     
            )
     
        [Q] => Array
            (
                [0] => Array
                    (
                        [city_id] => 1
                        [city_name] => 全国
                        [ename] => QuanGuo
                        [letter] => Q
                        [city_content] => ADSFADSFA
                        [order_desc] => 1
                        [display] => 1
                        [short_description] => ADSFADF
                        [keyword] => AF,ASDF,ADF,
                        [create_name] => 
                        [create_time] => 
                    )
     
            )
     
        [T] => Array
            (
                [1] => Array
                    (
                        [city_id] => 9
                        [city_name] => 台州
                        [ename] => TaiZhou
                        [letter] => T
                        [city_content] => AAAA
                        [order_desc] => AAA
                        [display] => 1
                        [short_description] => AAA
                        [keyword] => AAA
                        [create_name] => xiaozi
                        [create_time] => 1310525878
                    )
     
                [3] => Array
                    (
                        [city_id] => 11
                        [city_name] => ASDFASDFADSF
                        [ename] => ASDFASDFASDF
                        [letter] => T
                        [city_content] => 222ss
                        [order_desc] => 22
                        [display] => 1
                        [short_description] => 22
                        [keyword] => ss
                        [create_name] => zongzi
                        [create_time] => 1310701443
                    )
     
            )
     
    )
    得到了我想要的!
  • 相关阅读:
    mysql自定义函数多表更新:update_order_relation()
    mysql自定义函数初始化数据:init_data()
    关于tomcat启动错误:At least one JAR was scanned for TLDs yet contained no TLDs
    intellij debug模式提示 Method breakpoints may dramatically slow down debugging
    Linux开机启动流程详细步骤是什么?
    chkconfig 添加脚本开机自启动
    优化SSH配置(一键完成增加若干参数)
    linux目录整理
    linux命令整理
    buffer和cache有什么区别?
  • 原文地址:https://www.cnblogs.com/wangzong/p/2111640.html
Copyright © 2020-2023  润新知