PHP 二维数组排序 便利~
程序员文章站
2024-01-30 14:57:04
...
PHP 二维数组排序 方便~~
array_multisort() 对二维数组进行排序http://www.ucantech.net/网站推广
数组$roughData,我们打算按照accurancy排序。
Array
(
[0] => Array
(
[username] => 10yl
[accuracy] => 0.00
)
[1] => Array
(
[username] => 11yl
[accuracy] => 1.00
)
[2] => Array
(
[username] => 12yl
[accuracy] => 0.00
)
[3] => Array
(
[username] => 13yl
[accuracy] => 1.00
)
)
方法:
(1)提取accuracy列数组
foreach ($roughData as $key => $row) {
$usernames[$key] = $row['username'];
$accuracy[$key] = $row['accuracy'];
}
(2)进行排序
array_multisort($accuracy, SORT_ASC,$roughData);
当print_r($roughData);后我们将得到一个按accuracy升序排序的二维数组(fblww-1230)
array_multisort() 对二维数组进行排序http://www.ucantech.net/网站推广
数组$roughData,我们打算按照accurancy排序。
Array
(
[0] => Array
(
[username] => 10yl
[accuracy] => 0.00
)
[1] => Array
(
[username] => 11yl
[accuracy] => 1.00
)
[2] => Array
(
[username] => 12yl
[accuracy] => 0.00
)
[3] => Array
(
[username] => 13yl
[accuracy] => 1.00
)
)
方法:
(1)提取accuracy列数组
foreach ($roughData as $key => $row) {
$usernames[$key] = $row['username'];
$accuracy[$key] = $row['accuracy'];
}
(2)进行排序
array_multisort($accuracy, SORT_ASC,$roughData);
当print_r($roughData);后我们将得到一个按accuracy升序排序的二维数组(fblww-1230)
相关文章
相关视频
上一篇: 如何用正则截取域名中间的部分
下一篇: php视频拍照上传头像功能实现代码分享