Skip to content Skip to sidebar Skip to footer

php数组怎么根据其中的一个值进行排序?

$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得到如下结果,满足需求。

原文地址: https://www.cnblogs.com/lzijiangg/p/11731298.html

Leave a comment