天天看点

php 二维数组排序问题

标题遇到的问题 记录上 留用

$data = array(
	0=>array('time'=>'2019-05-24 10:09:33','a'=>'time'),
	1=>array('time'=>'2019-05-28 03:23:22','b'=>'kaishi'),
	2=>array('time'=>'2019-05-21 18:33:11','c'=>'sdkfl'),
	3=>array('time'=>'2019-05-23 08:21:34','d'=>'sdf')

);

//$a = array_column($data, 'time');
echo '<pre>';
array_multisort(array_column($data, 'time'),SORT_ASC,$data);

var_dump($data);
           
结果
array(4) {
  [0]=>
  array(2) {
    ["time"]=>
    string(19) "2019-05-21 18:33:11"
    ["c"]=>
    string(5) "sdkfl"
  }
  [1]=>
  array(2) {
    ["time"]=>
    string(19) "2019-05-23 08:21:34"
    ["d"]=>
    string(3) "sdf"
  }
  [2]=>
  array(2) {
    ["time"]=>
    string(19) "2019-05-24 10:09:33"
    ["a"]=>
    string(4) "time"
  }
  [3]=>
  array(2) {
    ["time"]=>
    string(19) "2019-05-28 03:23:22"
    ["b"]=>
    string(6) "kaishi"
  }
}