Heim > Artikel > Backend-Entwicklung > 多维数组排序有关问题
多维数组排序问题
有一数组:
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $arr = array(array(1,0),array(2,0),array(3,0),array(4,0),array(5,1),array(6,1),array(7,5),array(8,2)); ?>
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $arr = array(array(1,0),array(5,1),array(7,5),array(6,1),array(2,0),array(8,2),array(3,0),array(4,0)); ?>
$arr = array(array(1,0),array(2,0),array(3,0),array(4,0),array(5,1),array(6,1),array(7,5),array(8,2));print_r(foo($arr));function foo($ar, $p=0) { $r = array(); foreach($ar as $v) { if($v[1] == $p) { $r[] = $v; $r = array_merge($r, foo($ar, $v[0])); } } return $r;}<div class="clear"> </div>