------解决方案--------------------<?<br />$arr = array(<br /> <br /> array('id'=>1,'city_name'=>'中国','rel_id'=>'1','pid'=>0),<br /> array('id'=>2,'city_name'=>'广东','rel_id'=>'1-2','pid'=>1),<br /> array('id'=>3,'city_name'=>'深圳','rel_id'=>'1-2-3','pid'=>2),<br /> array('id'=>4,'city_name'=>'广州','rel_id'=>'1-2-4','pid'=>2)<br /> <br />);<br /> <br />function find_subclass( $pid ){<br /> <br /> global $arr;<br /> $__arr = array();<br /> foreach ( $arr as $k=>$v )<br /> {<br /> <br /> if( $v['pid']==$pid )$__arr[] = $v;<br /> <br /> }<br /> return $__arr;<br /> <br />}<br /> <br />function tree_subclass($pid=0){<br /> <br /> $__arr = array();<br /> $__arr = find_subclass($pid);<br /> if( !empty($__arr) ){<br /> <br /> foreach ( $__arr as $k=>$v )<br /> {<br /> <br /> $__arr[$k]['subclass'] = tree_subclass($v['id']);<br /> <br /> }<br /> <br /> }<br /> return $__arr;<br />}<br /> <br />var_dump(tree_subclass(0));<br /> <br />?>
------解决方案--------------------见http://bbs.csdn.net/topics/390364669