Two-dimensional array sorted by a key value for PHP

Source: Internet
Author: User
$arr =[    Array (        ' name ' = ' small Bad dragon ',        ' age ' =>28    ),    Array (        ' name ' = ' small bad Dragon 2 ',        ' age ' = >14    ),    Array (        ' name ' = ' small bad Dragon 3 ',        ' age ' =>59    ),    Array (        ' name ' = ' small bad Dragon 4 ',        ' age ' =>23    ,    Array (        ' name ' = ' = ' small bad Dragon 5 ',        ' age ' =>23    ),    array (        ' Name ' = ' ' small bad Dragon 6 ',        ' age ' =>21    ,]; Array_multisort (Array_column ($arr, ' age '), Sort_desc, $arr);p Rint_r ($arr);

  

where Array_column (an array, a key value in an array) returns a one-dimensional array from a column that extracts a key value from a multidimensional array;

Array_multisort (Array (one-dimensional array), sort (SOTR_ASC,SOTR_DESC), other array (can be two-dimensional))

Two-dimensional array sorted by a key value for PHP

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.