Last active
January 7, 2020 07:37
-
-
Save haxianhe/1881f6b8c23b35afed644cd4c44baaef to your computer and use it in GitHub Desktop.
PHP 对数据库结果排序(对多维数组排序)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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