时间:2021-07-01 10:21:17 帮助过:20人阅读
$a = Array( '0' => Array('id' => 3,'sid' => 0), '1' => Array('id' => 4,'sid' => 0), '2' => Array('id' => 5,'sid' => 3), '3' => Array('id' => 6,'sid' => 0), '4' => Array('id' => 7,'sid' => 4), '5' => Array('id' => 8,'sid' => 0), ); function cmsort($ar, $sid=0, &$res=array()) { foreach($ar as $r) { if($r['sid'] == $sid) { $res[] = $r; cmsort($ar, $r['id'], $res); } } return $res; } var_export(cmsort($a));