Share a simple way to sort a two-dimensional array, how to handle

Source: Internet
Author: User
A simple way to share a two-dimensional array ordering
PHP Code
  
   function Array_sort ($arr, $field, $by =sort_asc)    {                   foreach ($arr as $v) {              $r [] = $v [$field];            }         Array_multisort ($r, $by, $arr);         return $arr;    }    $array = Array (                     ´name´=>´ mobile ´,´brand´=>´ nokia ´,´price´=>3000),                      array (´name´=>´ laptop ´,´ brand´=>´lenovo´,´price´=>4000),                    );    $a =array_sort ($array, ´price´,sort_desc);    echo "
";    Print_r ($a);  


Welcome to use ...



------Solution--------------------
It's always been this ah, hehe.
------Solution--------------------
It's better not to encapsulate it. Direct Array_multisort
------Solution--------------------
There are automatic sorting functions in PHP.
------Solution--------------------
Do you want to encapsulate one of the three-dimensional arrays?
------Solution--------------------
discuss

Do you want to encapsulate one of the three-dimensional arrays?
  • 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.