例如有一个这样的数组结构,我想要根据里面的sort的大小进行排序。
一、php函数
依次使用这两个php函数就可实现
1、array_column() 返回输入数组中某个单一列的值
2、array_multisort() 函数返回一个排序数组
$cmf_settings = array(
array (
"url" => "img/20191015/5da586020fa6b.jpg",
"alt" => "lunbo2",
"href" => "https://www.baidu.com/",
"sort" => "7"
),
array(
"url" => "img/20191018/5da9783499dec.jpg",
"alt" => "X1300",
"href" => "https://www.baidu.com/fully-automatic-pallet-wrappin/x1300-180.html",
"sort" => "3"
),
array(
"url" => "img/20191018/5da987c81f420.jpg",
"alt" => "S300",
"href" => "https://www.baidu.com/fully-automatic-pallet-wrappin/s300-170.html",
"sort" => "4"
)
);
$cmf_arr = array_column($cmf_settings, 'sort');
array_multisort($cmf_arr, SORT_ASC, $cmf_settings);
//打印$cmf_settings
var_dump($cmf_settings);