dongtiao2066 2012-07-19 10:13 采纳率: 0%
浏览 22
已采纳

排序多维数组[重复]

Possible Duplicate:
How do I sort a multidimensional array in php

I have multidimensional array, for exaple this:

$mas = array("s",array("c","b","a"),array(3,5,1),"a",array("s",array("z","a")));

I want sort (ascending) all array-elements, i write recursive function, but it is not working, please tell me, who I have a wrong ?

$mas = array("s",array("c","b","a"),array(3,5,1),"a",array("s",array("z","a")));



function sortsort($m) {
    sort($m);
    foreach ($m as &$v) {
        if (is_array($v)) {
             sortsort($v);
        }
    }
    return $m;
}



  var_dump(sortsort($mas));
  • 写回答

2条回答 默认 最新

  • donglei1616 2012-07-19 10:26
    关注

    try this

    $mas = array("s",array("c","b","a"),array(3,5,1),"a",array("s",array("z","a")));
    function sortsort(&$m) {
        sort($m);
        foreach ($m as $k=>$v) {
            if (is_array($v)) {
                 sortsort($m[$k]);
            }
        }
        return $m;
    }
    
    print_r(sortsort($mas));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?