这里利用数组来做实例,有需要的要改成数据库查询然后再存到数据操作,实例代码如下:
<?php $a = array( 'AAAAAA' => array( 'aaaaaa' => array( '111111', '222222', '333333' ), 'bbbbbb' => array( '111111', '222222', '333333' ), 'cccccc' => array( '111111', '222222', '333333' ), ), 'BBBBBB' => array( 'aaaaaa' => array( '111111', '222222', '333333' ), 'bbbbbb'=> array( '111111', '222222', '333333' ), 'cccccc'=> array( '111111', '222222', '333333' ), ), 'CCCCCC' => array( 'aaaaaa'=> array( '111111', '222222', '333333' ), 'bbbbbb'=> array( '111111', '222222', '333333' ), 'cccccc' => array( '111111', '222222', '333333' ), ), ); foreach ($a as $k=>$v){ echo $k."<br>"; // if(is_array($v)){ foreach($v as $key=>$val){ echo " ".$key."<br>"; // } if(is_array($val)){ foreach($val as $kkk=>$vall){ echo " ".$vall."<br>"; } } } echo "<br>"; } /*******mysql查询无限级分类的代码******/ /*** $sql = "SELECT a.Title AS big, b.Title AS small FROM largeTitle AS a LEFT JOIN smallTitle AS b ON a.ID=b.LargeID"; $a = array(); $r = mysql_query($sql); while( $arr = mysql_fetch_array($r)){ $a[$arr['big']] = $arr['small']; } ***/