排序的多维阵列 [英] Sort a multi-dimensional array

查看:122
本文介绍了排序的多维阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要排序从而重新presents文件系统结构的多维数组:

I need to sort a multi-dimensional array which represents filesystem structure:

Array
(
    [dir1] => Array
        (
            [dir2] => Array
                (
                    [dir3] => Array
                        (
                            [dir4] => Array
                                (
                                    [0] => file1.php
                                    [1] => abc.php
                                )

                        )

                    [0] => file2.php
                    [1] => abc.php
                )

        )

    [abc] => Array
        (
            [abc] => Array
                (
                    [abc] => Array
                        (
                            [0] => file5.php
                        )

                )

        )

)

我不知道什么是算法。

I have no idea what is the algorithm.

推荐答案

http://php.net/sort# 51088

替换排序($ a)于mulsort功能由ksort开始($ A)

replace sort($a) at the beginning of the mulsort function by ksort($a)

编辑:对不起,只是改变了mulsort code为:

sorry, just change the mulsort code to :

function mulsort(&$a)
{
 ksort($a);
 foreach($a as &$value)
    if (is_array($value))
        mulsort($value);
}

这篇关于排序的多维阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆