Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP多数组排序_Php_Arrays_Sorting - Fatal编程技术网

PHP多数组排序

PHP多数组排序,php,arrays,sorting,Php,Arrays,Sorting,我需要按数组中的一个值对多个数组进行排序。不幸的是,我无法在数据库中对此进行排序。我只能得到这样的数组 我的阵列看起来像: Array ( [0] => Array ( [id] => 10913 [name] => NAME 1 [logo_img] => 28361bd6114a32daafcf150da5ee1d33.jpeg [has_frame

我需要按数组中的一个值对多个数组进行排序。不幸的是,我无法在数据库中对此进行排序。我只能得到这样的数组

我的阵列看起来像:

Array
(
    [0] => Array
        (
            [id] => 10913
            [name] => NAME 1
            [logo_img] => 28361bd6114a32daafcf150da5ee1d33.jpeg
            [has_frame] => t
            [weight] => 0
        )

    [1] => Array
        (
            [id] => 10902
            [name] => Name 2
            [logo_img] => d0642d5efeabe8b861f2f32fa17f35b3.jpeg
            [has_frame] => t
            [weight] => 4
        )

    [2] => Array
        (
            [id] => 8887
            [name] => Some name 3
            [logo_img] => 12e47533604438bf390d69218434b630.jpeg
            [has_frame] => f
            [weight] => 0
        )

    [3] => Array
        (
            [id] => 49
            [name] => Some name 4
            [logo_img] => 5971148b049c5bb0b6e402a1de1836ef.jpeg
            [has_frame] => t
            [weight] => 0
        )

    [4] => Array
        (
            [id] => 10871
            [name] => name2
            [logo_img] => 7dcc1a6058a81b4e45de5f2274025907.jpeg
            [has_frame] => t
            [weight] => 0
        )

    [5] => Array
        (
            [id] => 1880
            [name] => name 4
            [logo_img] => dc05764ea71425a4a653b81997e7d929.jpeg
            [has_frame] => f
            [weight] => 0
        )

    [6] => Array
        (
            [id] => 9678
            [name] => name 33
            [logo_img] => 8ded98244a6928d5179398fa9d3b59bc.jpeg
            [has_frame] => t
            [weight] => 5
        )

    [7] => Array
        (
            [id] => 2880
            [name] => name r
            [logo_img] => 09876329a5ac2a84e9f83923c75e780c.jpeg
            [has_frame] => f
            [weight] => 0
        )

    [8] => Array
        (
            [id] => 8265
            [name] => name 5
            [logo_img] => 487ed3c676666e380f813f5f1a9fb040.jpeg
            [has_frame] => t
            [weight] => 1
        )

)
我需要按重量元素说明订购此阵列。可以吗

这列出了很多关于排序的信息

如果需要使用键进行排序,请尝试

ksort($array)

这列出了很多关于排序的信息

如果需要使用键进行排序,请尝试

ksort($array)
我就是这样做的:

usort($object, 'cmp');

function cmp($a, $b)
{
    return strcmp($b['weigth'], $a['weigth']); // or -> weigth
}
我就是这样做的:

usort($object, 'cmp');

function cmp($a, $b)
{
    return strcmp($b['weigth'], $a['weigth']); // or -> weigth
}
//您可以使用'uasort',它有一个可由用户定义的比较函数;
//如果整个数组的名称为$array
//定义函数
函数比较($obj1,$obj2){
如果($obj1['weight']=$obj2['weight'])){
返回0;
}
返回$obj1['weight']
//您可以使用'uasort',该'uasort'具有可由用户定义的比较函数;
//如果整个数组的名称为$array
//定义函数
函数比较($obj1,$obj2){
如果($obj1['weight']=$obj2['weight'])){
返回0;
}

return$obj1['weight']是的,这是可能的。到目前为止您尝试了什么?请参阅我尝试了数组\u multisort(),但没有效果。也可以帮助您。这可以帮助您。是的,这是可能的。到目前为止您尝试了什么?请参阅我尝试了数组\u multisort(),但没有效果。也可以帮助您。这可以帮助您