比如数组是这样的:
  $example = array( array('b'=>7, 'rsd'=>6, 'gdd'=>3),
                    array('d'=>5, 'ess'=>8, 'ffs'=>5),
            array('c'=>2, 'sdv'=>5, 'vfs'=>6),
            array('a'=>8, 'hds'=>4, 'rfs'=>9));
不要用PHP系统函数,用uasort()或者uksort(),怎么写自定义的函数传进去?
function compare($X, $Y)
这么用uasort($example, 'compare'),
这个compare该怎么写?不是关联型的二维数组我知道怎么写compare,  function compare($x, $y)
  {
  if($x[0] == $y[0])
    return 0;
  elseif($x[0] < $y[0])
    return -1;
  else
    return 1;
  }

解决方案 »

  1.   

    手册 array_multisort 
    看例#4
      

  2.   

    http://www.php100.com/manual/php/
    看了这个网站的array_multisort,例子直到#3
      

  3.   

    Example #4 对数据库结果进行排序
     本例中 data数组中的每个单元表示一个表中的一行。这是典型的数据库记录的数据集合。 
    例子中的数据如下: 
    volume | edition
    -------+--------
        67 |       2
        86 |       1
        85 |       6
        98 |       2
        86 |       6
        67 |       7
     数据全都存放在名为 data的数组中。这通常是通过循环从数据库取得的结果,例如 mysql_fetch_assoc()。 
    <?php
    $data[] = array('volume' => 67, 'edition' => 2);
    $data[] = array('volume' => 86, 'edition' => 1);
    $data[] = array('volume' => 85, 'edition' => 6);
    $data[] = array('volume' => 98, 'edition' => 2);
    $data[] = array('volume' => 86, 'edition' => 6);
    $data[] = array('volume' => 67, 'edition' => 7);
    ?> 
    本例中将把 volume 降序排列,把 edition 升序排列。 
    现在有了包含有行的数组,但是 array_multisort()需要一个包含列的数组,因此用以下代码来取得列,然后排序。 
    <?php
    // 取得列的列表
    foreach ($data as $key => $row) {
        $volume[$key]  = $row['volume'];
        $edition[$key] = $row['edition'];
    }// 将数据根据 volume 降序排列,根据 edition 升序排列
    // 把 $data 作为最后一个参数,以通用键排序
    array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
    ?> 
    数据集合现在排好序了,结果如下: 
    volume | edition
    -------+--------
        98 |       2
        86 |       1
        86 |       6
        85 |       6
        67 |       2
        67 |       7