php二维数据排序

2019-02-25 12:30:13   php

  php  

  1. $members = $this->arraySort($members,'updatedTime');
  2. if ('unfinished' == $queryType) {
  3. $members = $this->arraySort($members,'status');
  4. $members = $this->arraySort($members,'updatedTime');
  5. }
  6. /**
  7. * 二维数组根据某个字段排序
  8. * @param array $array 要排序的数组
  9. * @param string $keys 要排序的键字段
  10. * @param string $sort 排序类型 SORT_ASC SORT_DESC
  11. * @return array 排序后的数组
  12. */
  13. function arraySort($array, $keys, $sort = SORT_DESC) {
  14. $keysValue = array();
  15. foreach ($array as $k => $v) {
  16. $keysValue[$k] = $v[$keys];
  17. }
  18. array_multisort($keysValue, $sort, $array);
  19. return $array;
  20. }