PHP implementation of the specified field of multi-dimensional array sorting function sharing, multidimensional array _php tutorial

Source: Internet
Author: User

PHP implementation of the specified field of multidimensional array sorting function sharing, multidimensional array


The PHP array sort can be implemented with the Array_multisort method, but if it is a multidimensional array, and we want to specify a field in the array to sort, then we need to write our own method implementation. This article shares the code for a multidimensional array ordering method for a specified field in PHP, which can be sorted by an array of field fields.
Copy the Code code as follows:
Function Sortarrbyfield (& $array, $field, $desc = False) {
$FIELDARR = Array ();
foreach ($array as $k = = $v) {
$FIELDARR [$k] = $v [$field];
}
$sort = $desc = = False? Sort_asc:sort_desc;
Array_multisort ($FIELDARR, $sort, $array);
}

The above is the PHP specified field of multidimensional array sorting method, I hope this PHP code to help you.

http://www.bkjia.com/PHPjc/965357.html www.bkjia.com true http://www.bkjia.com/PHPjc/965357.html techarticle PHP Implementation of the specified field of multi-dimensional array sorting function sharing, multidimensional array of PHP array ordering can be implemented with the Array_multisort method, but if it is a multidimensional array, and we want to specify the array ...

  • 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.