欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

多维数组排序解决思路

程序员文章站 2022-06-15 17:52:04
...
多维数组排序
如下
PHP code
 1
    ['total'] => 2274
    ['rows'] => Array
    (
        [0] => Array
        (
            ['id'] => 12
            ['cell'] => Array
            (
                ['fid'] => 12
                ['number'] => 3
            )

        )

        [1] => Array
        (
            ['id'] => 13
            ['cell'] => Array
            (
                ['fid'] => 13
                ['number'] => 5
            )

        )

        [2] => Array
        (
            ['id'] => 14
            ['cell'] => Array
            (
                ['fid'] => 14
                ['number'] => 2
            )

        )

        [3] => Array
        (
            ['id'] => 15
            ['cell'] => Array
            (
                ['fid'] => 15
                ['number'] => 4
            )

        )

        [4] => Array
        (
            ['id'] => 16
            ['cell'] => Array
            (
                ['fid'] => 16
                ['number'] => 10
            )

        )

    )

);


想变成
$arr = Array
(
['page'] => 1
['total'] => 2274
['rows'] => Array
(
[0] => Array
(
['id'] => 12
['cell'] => Array
(
['fid'] => 12
['number'] => 2
)

)

[1] => Array
(
['id'] => 13
['cell'] => Array
(
['fid'] => 13
['number'] => 3
)

)

[2] => Array
(
['id'] => 14
['cell'] => Array
(
['fid'] => 14
['number'] => 4
)

)

[3] => Array
(
['id'] => 15
['cell'] => Array
(
['fid'] => 15
['number'] => 5
)

)

[4] => Array
(
['id'] => 16
['cell'] => Array
(
['fid'] => 16
['number'] => 10
)

)

)

);[/code]
不知大家有没有好的做法


------解决方案--------------------
什么规则?按照number从小到大?

------解决方案--------------------
建议你格式化后贴出来,记得贴 var_export($arr); 后的结果。这样太伤眼睛了。
------解决方案--------------------
usort
------解决方案--------------------
原始数据
1 => array ( 'id' => 13, 'cell' => array ( 'fid' => 13, 'number' => 5, ), )
怎么变成了
1 => array ( 'id' => 13, 'cell' => array ( 'fid' => 13, 'number' => 3, ), )
多维数组排序解决思路

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频