モデレータの xuzuning に質問します
<br /> $ar = array (<br /> array("level" => '1', "caption" => "一级菜单1"),<br /> array("level" => '1', "caption" => "一级菜单2"),<br /> array("level" => '2', "caption" => "二级菜单1"),<br /> array("level" => '2', "caption" => "二级菜单2"),<br /> array("level" => '3', "caption" => "三级菜单1"),<br /> array("level" => '1', "caption" => "一级菜单3"),<br /> );<br /> print_r( foo($ar));<br /> <br /> function foo(&$ar, $level='1') {<br /> $res = array();<br /> while($r = current($ar)) {<br /> if($r['level'] > $level) $res[count($res)-1]['sub'] = foo($ar, $r['level']);<br /> elseif($r['level'] == $level) $res[] = $r;<br /> else {<br /> array_unshift($ar, $r);<br /> break;<br /> }<br /> array_shift($ar);<br /> }<br /> return $res;<br /> }<br />