欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php无限级分类程序

程序员文章站 2022-06-12 14:46:11
...
这里利用数组来做实例,有需要的要改成数据库查询然后再存到数据操作,实例代码如下:
  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."
"; // if(is_array($v)){ foreach($v as $key=>$val){ echo " ".$key."
"; // } if(is_array($val)){ foreach($val as $kkk=>$vall){ echo " ".$vall."
"; } } } echo "
"; } /*******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']; } ***/