Skip to content

Instantly share code, notes, and snippets.

@haxianhe
Last active January 7, 2020 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haxianhe/1881f6b8c23b35afed644cd4c44baaef to your computer and use it in GitHub Desktop.
Save haxianhe/1881f6b8c23b35afed644cd4c44baaef to your computer and use it in GitHub Desktop.
PHP 对数据库结果排序(对多维数组排序)
<?php
$data[] = array('volume' => 67, 'edition' => 2);
$data[] = array('volume' => 86, 'edition' => 1);
$data[] = array('volume' => 85, 'edition' => 6);
$data[] = array('volume' => 98, 'edition' => 2);
$data[] = array('volume' => 86, 'edition' => 6);
$data[] = array('volume' => 67, 'edition' => 7);
print_r($data);
$column = array_column($data, 'edition');
array_multisort($column, SORT_DESC, $data);
print_r($data);
//如果要排序的字段是字符串,需使用 SORT_STRING 进行排序
//array_multisort($columns, SORT_STRING, $result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment