PHP implementation of two-dimensional array time sequencing

Source: Internet
Author: User
This article mainly introduces the PHP two-dimensional array time sorting implementation code, the need for friends can refer to the following

Yesterday to sort the array of time to find, to sort by time, but PHP did not have this function, so found on the Internet this code, the first parameter is an array, the second is to sort the elements, the third is a sort of way,

Here is the code for PHP two-dimensional array ordering

function ArraySort ($arr, $keys, $type = ' asc ') {    $keysvalue = $new _array = Array ();    foreach ($arr as $k = + $v) {      $keysvalue [$k] = $v [$keys];    }    $type = = ' ASC '? Asort ($keysvalue): Arsort ($keysvalue);    Reset ($keysvalue);    foreach ($keysvalue as $k = + $v) {      $new _array[$k] = $arr [$k];    }    return $new _array;  } $arr [] = Array ("name" = "1", "Time" =>1), $arr [] = Array ("name" = "2", "Time" =>2), ArraySort ($arr, "Time", " Desc ");


The above is the whole content of this article, I hope that everyone's study has helped.


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.