首頁 > 後端開發 > php教程 > 多维数组排序解决思路

多维数组排序解决思路

WBOY
發布: 2016-06-13 13:16:42
原創
902 人瀏覽過

多维数组排序
如下

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php [code=PHP]$arr = Array
(
    ['page'] => 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, ), )
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板