PHP 2D array sorting convenience ~

Source: Internet
Author: User
PHP 2D array sorting convenience ~~ Array_multisort () sorts two-dimensional arrays www.ucantech.net website promotion array $ roughData. we plan to sort them by accurancy. Array (& nbsp; [0] & gt; Array & nbsp; & PHP 2D array sorting convenience ~~
Array_multisort () sorts two-dimensional arrays http://www.ucantech.net/website promotion
Array $ roughData, which we plan to sort by accurancy.

Array
(
[0] => Array
(
[Username] => 10yl
[Accuracy] = & gt; 0.00
)

[1] => Array
(
[Username] => 11yl
[Accuracy] = & gt; 1.00
)

[2] => Array
(
[Username] => 12yl
[Accuracy] = & gt; 0.00
)

[3] => Array
(
[Username] => 13yl
[Accuracy] = & gt; 1.00
)
)

Method:
(1) extract an array of accuracy columns

Foreach ($ roughData as $ key => $ row ){
$ Usernames [$ key] = $ row ['username'];
$ Accuracy [$ key] = $ row ['accuracy '];
}

(2) sorting

Array_multisort ($ accuracy, SORT_ASC, $ roughData );

When print_r ($ roughData); then we will get a two-dimensional array (fblww-1230) sorted in ascending order by accuracy)

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.