php- two-dimensional array sorting

 How do you sort order for a column in which the value of two-dimensional array? $ Arr = [[ 'a' => 2], [ 'a' => 1], [ 'a' => 3]]

 

(1) uasourt function, the more flexible and can be sorted according to their wishes

    uasourt($arr, function($p1, $p2) {

      if ($p1['a'] == $p2['a']) return 0;

      return $p1['a'] > $p2['a'] ? 1 : -1;

    })

 

(2) array_multisort This function will sort the first array, the second array element position of the first array followed by transformation with

  foreach($arr as $k => $v)

    $sort[$k] = $v['a'];

  array_multisort($sort, $arr);

 

Guess you like

Origin www.cnblogs.com/wangjianheng/p/11498763.html