美文网首页
常用数据格式化一

常用数据格式化一

作者: lovehamburger | 来源:发表于2017-08-25 14:25 被阅读0次
    $res=Array
    (
        [0] => Array
            (
                [name] => 文章管理
                [icon] => icon-file-text
                [menu_id] => 2
                [parent_menu_id] => 1
                [menu_en_name] => AM_ARTICLE_LIST
                [menu_ch_name] => 文章列表
                [menu_icon] => 
                [menu_url] => Admin-ArticleManage-classConfigTree
                [menu_sort] => 1
                [comments] => 
            )
    
        [1] => Array
            (
                [name] => 文章管理
                [icon] => icon-file-text
                [menu_id] => 3
                [parent_menu_id] => 1
                [menu_en_name] => AM_ARTICLE_ADD
                [menu_ch_name] => 添加文章
                [menu_icon] => 
                [menu_url] => Admin-ArticleManage-publish
                [menu_sort] => 2
                [comments] => 
            )
    
        [2] => Array
            (
                [name] => 文章管理
                [icon] => icon-file-text
                [menu_id] => 4
                [parent_menu_id] => 1
                [menu_en_name] => AM_ARTICLE_LIST_MANAGE
                [menu_ch_name] => 栏目管理
                [menu_icon] => 
                [menu_url] => Admin-ArticleManage-classConfig
                [menu_sort] => 3
                [comments] => 
            )
    
        [3] => Array
            (
                [name] => 及时通讯
                [icon] => icon-envelope-alt
                [menu_id] => 35
                [parent_menu_id] => 34
                [menu_en_name] => AM_INSTANT_MESSAGE
                [menu_ch_name] => 及时消息
                [menu_icon] => 
                [menu_url] => Admin-Message-MqMsg
                [menu_sort] => 1
                [comments] => 
            )
    )
    

    以上数组由mysql联表查询得到的数据,但存在数据重复,无主副标题的差异固需将数据通过php重新格式话:

    #重新定义一个新数组:
    $menu = array();
    foreach($res as  $key $value){
         $menu[$value['name']]['name'] = $value['name'];
         $menu[$value['name']]['icon'] = $value['icon'];
         $menu[$value['name']]['class'][$value['menu_id']] = $value['menu_url'];
         $menu[$value['name']]['class'][$value['menu_id']] = $value['menu_ch_name'];
         $menu = array_values($menu);
    
            echo'<pre>'; 
            print_r($menu); 
            echo'</pre>';
    }

    相关文章

      网友评论

          本文标题:常用数据格式化一

          本文链接:https://www.haomeiwen.com/subject/bdxlqxtx.html