This article mainly introduces the PHP two-dimensional array time sorting implementation code. Friends who need it can refer to it.
I discovered it yesterday when I wanted to sort the array. I need to sort by time, but PHP does not have a built-in This function, so I found this code on the Internet. The first parameter is the array, the second is the element to be sorted, and the third is the sorting method.
The following is the code for php two-dimensional array sorting
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 entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
phpHow to use curl to simulate IP and source for access
How to display hexadecimal image data on the img tag of html in PHP
phpImplement the method of deleting the specified element from the array
The above is the detailed content of PHP implements two-dimensional array time sorting. For more information, please follow other related articles on the PHP Chinese website!