This article mainly introduces the PHP two-dimensional array according to the specified field of the implementation of the order, has a certain reference value, now share to everyone, the need for friends can refer to
Problem: After merging two arrays with PHP's Array_merge () function, you want to sort the new array by the ' post_time ' field in the two arrays
Workaround: By consulting the official manual, I learned that there is a function of Array_multisort () that can sort multiple arrays or multidimensional arrays, returning an array after sorting, where the string key name is preserved, but the number key name is re-indexed, starting at 0 and incrementing by 1.
This function is encapsulated below for easy invocation:
/** * A two-dimensional array is sorted by the specified field * @params array $array needs to be sorted * @params string $field sorted field * @params string $sort sort order Flag Sort_desc Descending; Sort_asc Ascending */function arraysequence ($array, $field, $sort = ' Sort_desc ') { $arrSort = array (); foreach ($array as $uniqid + $row) { foreach ($row as $key + = $value) { $arrSort [$key] [$uniqid] = $value;
} } array_multisort ($arrSort [$field], constant ($sort), $array); return $array;}
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!