时间:2021-07-01 10:21:17 帮助过:28人阅读
$a = array( array('name'=>'a','num'=>'1','parentNum'=>'0'), array('name'=>'b','num'=>'2','parentNum'=>'0'), array('name'=>'c','num'=>'3','parentNum'=>'0'), array('name'=>'d','num'=>'4','parentNum'=>'1'), array('name'=>'e','num'=>'5','parentNum'=>'2'), array('name'=>'f','num'=>'6','parentNum'=>'0'), array('name'=>'g','num'=>'7','parentNum'=>'0'),)
array('name'=>'a','num'=>'1','parentNum'=>'0'), array('name'=>'d','num'=>'4','parentNum'=>'1'), array('name'=>'b','num'=>'2','parentNum'=>'0'), array('name'=>'e','num'=>'5','parentNum'=>'2'), array('name'=>'c','num'=>'3','parentNum'=>'0'), array('name'=>'f','num'=>'6','parentNum'=>'0'), array('name'=>'g','num'=>'7','parentNum'=>'0'),
$a = array( array('name'=>'a','num'=>'1','parentNum'=>'0'), array('name'=>'b','num'=>'2','parentNum'=>'0'), array('name'=>'c','num'=>'3','parentNum'=>'0'), array('name'=>'d','num'=>'4','parentNum'=>'1'), array('name'=>'e','num'=>'5','parentNum'=>'2'), array('name'=>'f','num'=>'6','parentNum'=>'0'), array('name'=>'g','num'=>'7','parentNum'=>'0'),);foreach($a as $r) { $p[] = $r['parentNum'] ? $r['parentNum'] : $r['num'];}array_multisort($p, $a);print_r($a);
Array( [0] => Array ( [name] => a [num] => 1 [parentNum] => 0 ) [1] => Array ( [name] => d [num] => 4 [parentNum] => 1 ) [2] => Array ( [name] => b [num] => 2 [parentNum] => 0 ) [3] => Array ( [name] => e [num] => 5 [parentNum] => 2 ) [4] => Array ( [name] => c [num] => 3 [parentNum] => 0 ) [5] => Array ( [name] => f [num] => 6 [parentNum] => 0 ) [6] => Array ( [name] => g [num] => 7 [parentNum] => 0 ))
这个情况有点理想化了,实际中却不对,还是谢谢了
那是,但我也不能无中生有
其实你的这个问题跟本就不是排序能解决的
精华区中有很多帖子,你应该认真看看
如果排序就能解决邻接列表的查询问题,那还需那么多人去研究他吗?
那是,但我也不能无中生有
其实你的这个问题跟本就不是排序能解决的
精华区中有很多帖子,你应该认真看看
如果排序就能解决邻接列表的查询问题,那还需那么多人去研究他吗?