二维数组按某一字段排序

<?php

//数组$list

$list=array(
array(
‘id’=>1,
‘title’=>’安全’,
‘inputtime’=>1571633101
),
array(
‘id’=>3,
‘title’=>’考试’,
‘inputtime’=>1571632131
),
array(
‘id’=>2,
‘title’=>’记录’,
‘inputtime’=>1571231101
)
);

//数据处理排序
$ids = array_column($list,’id’);
array_multisort($ids,SORT_ASC,$list);

//新的$list

$list=array(
array(
‘id’=>1,
‘title’=>’安全’,
‘inputtime’=>1571633101
),
array(
‘id’=>2,
‘title’=>’记录’,
‘inputtime’=>1571231101
),
array(
‘id’=>3,
‘title’=>’考试’,
‘inputtime’=>1571632131
),
);

二维数组按某一字段排序

发表评论

电子邮件地址不会被公开。 必填项已用*标注

滚动到顶部