PHP array sorting

Source: Internet
Author: User
The following array of fields Menu_order sort, how to solve??????

Array
(

[Menu] = = Array ([0] = = Array ([menu_name] = home [Login_menu                _name] = [icon] = Glyphicon Glyphicon-home [Menu_href] =/api/1ek2n5gsut/shop/ [Login_menu_href] =/api/1ek2n5gsut/shop/[Bind_action_attr] = 0 [men U_order] = 4) [1] = = Array ([menu_name] = i want to distribute [lo Gin_menu_name] = Distribution Center [icon] = Glyphicon Glyphicon-indent-left [Menu_href] =/ap i/1ek2n5gsut/distribute/join/[Login_menu_href] =/api/1ek2n5gsut/distribute/[bind_acti ON_ATTR] = 1 [Menu_order] = 3) [2] = = Array ([menu                _NAME] [Shopping cart] [login_menu_name] = [icon] = Glyphicon Glyphicon-shopping-cart [Menu_href]=/api/1ek2n5gsut/shop/cart/[Login_menu_href] =/api/1ek2n5gsut/shop/cart/[Bind_ac TION_ATTR] = 2 [Menu_order] + 1) [3] = = Array ([Me                Nu_name] = Personal Center [login_menu_name] [icon] = Glyphicon Glyphicon-user                [Menu_href] =/api/1ek2n5gsut/shop/member/[Login_menu_href] =/api/1ek2n5gsut/shop/member/            [Bind_action_attr] = 0 [Menu_order] = 1) [4] = = Array ([Menu_name] = [Login_menu_name] = [icon] = Glyphicon Glyp  hicon-th-list [Menu_href] =/api/1ek2n5gsut/shop/3//allcategory/[Login_menu_href] =             /api/1ek2n5gsut/shop/3//allcategory/[Bind_action_attr] = 0 [Menu_order] = )) [Method] =  

)

Reply content:

The following array of fields Menu_order sort, how to solve??????

Array
(

[Menu] = = Array ([0] = = Array ([menu_name] = home [Login_menu                _name] = [icon] = Glyphicon Glyphicon-home [Menu_href] =/api/1ek2n5gsut/shop/ [Login_menu_href] =/api/1ek2n5gsut/shop/[Bind_action_attr] = 0 [men U_order] = 4) [1] = = Array ([menu_name] = i want to distribute [lo Gin_menu_name] = Distribution Center [icon] = Glyphicon Glyphicon-indent-left [Menu_href] =/ap i/1ek2n5gsut/distribute/join/[Login_menu_href] =/api/1ek2n5gsut/distribute/[bind_acti ON_ATTR] = 1 [Menu_order] = 3) [2] = = Array ([menu                _NAME] [Shopping cart] [login_menu_name] = [icon] = Glyphicon Glyphicon-shopping-cart [Menu_href]=/api/1ek2n5gsut/shop/cart/[Login_menu_href] =/api/1ek2n5gsut/shop/cart/[Bind_ac TION_ATTR] = 2 [Menu_order] + 1) [3] = = Array ([Me                Nu_name] = Personal Center [login_menu_name] [icon] = Glyphicon Glyphicon-user                [Menu_href] =/api/1ek2n5gsut/shop/member/[Login_menu_href] =/api/1ek2n5gsut/shop/member/            [Bind_action_attr] = 0 [Menu_order] = 1) [4] = = Array ([Menu_name] = [Login_menu_name] = [icon] = Glyphicon Glyp  hicon-th-list [Menu_href] =/api/1ek2n5gsut/shop/3//allcategory/[Login_menu_href] =             /api/1ek2n5gsut/shop/3//allcategory/[Bind_action_attr] = 0 [Menu_order] = )) [Method] =  

)


  
    $row) {    $menu_order[$key] = $row['menu_order'];}// 将数据根据menu_order升序排列// 把 $menu 作为最后一个参数,以通用键排序array_multisort($menu_order, SORT_ASC, $menu);

Reference: http://php.net/manual/ja/function.array-multisort.php

Using a custom sort

usort($menu, function($a, $b) {    return $a['menu_order'] < $b['menu_order'] ? -1 : 1;});

Custom sort Find the value comparison for the corresponding node.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.