"PHP" php two-dimensional associative array to sort a value ____php

Source: Internet
Author: User
Tags sorts
$arr =array
(
[0] =array
(
[id] = 169,
[Sorts] = 4,
[Fans] = 0,
[Created_at] =1413621597
)


[1] =array
(
[id] = 170,
[Sorts] = 5,
[Fans] = 5,
[Created_at] =1418621597
)


[2] =array
(
[id] = 171,
[Sorts] = 1,
[Fans] = 9,
[Created_at] =1413621597
)

)

$arr is a two-dimensional associative array, the Array_multisort () function is required to sort the values of sorts in order/flashback.

The first argument for this function is an array (required, optional), and the second is sort SORT_ASC the default ascending order, Sort_desc descending, and the third sort_regular the default to arrange each item in a regular sequence, sort_numeric in numerical order, sort _string in alphabetical order, the fourth is the outer array $arr

foreach ($arr as $key => $value) {

$temp [$key]= $value [' sorts '];
}

Array_multisort ($temp, SORT_ASC, $arr);

Print_r ($arr);

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.