首页 >php教程 >php手册 >php无限级分类程序

php无限级分类程序

WBOY
WBOY原创
2016-05-25 16:43:251276浏览

这里利用数组来做实例,有需要的要改成数据库查询然后再存到数据操作,实例代码如下:

<?php 
	 
	$a = array( 
	  &#39;AAAAAA&#39;  =>  array( 
	        &#39;aaaaaa&#39; => array( 
	                 &#39;111111&#39;, 
	                 &#39;222222&#39;, 
	                 &#39;333333&#39; 
	        ), 
	        &#39;bbbbbb&#39;  => array( 
	                  &#39;111111&#39;, 
	                 &#39;222222&#39;, 
	                 &#39;333333&#39; 
	        ), 
	        &#39;cccccc&#39;  => array( 
	                  &#39;111111&#39;, 
	                  &#39;222222&#39;, 
	                  &#39;333333&#39; 
	        ),                       
	  ), 
	  &#39;BBBBBB&#39;  =>   array( 
	        &#39;aaaaaa&#39; => array( 
	                  &#39;111111&#39;, 
	                  &#39;222222&#39;, 
	                  &#39;333333&#39; 
	        ), 
	        &#39;bbbbbb&#39;=> array( 
	                  &#39;111111&#39;, 
	                  &#39;222222&#39;, 
	                  &#39;333333&#39; 
	        ), 
	        &#39;cccccc&#39;=> array( 
	                  &#39;111111&#39;, 
	                  &#39;222222&#39;, 
	                  &#39;333333&#39; 
	        ), 
	  ), 
	  &#39;CCCCCC&#39;  => array( 
	        &#39;aaaaaa&#39;=> array( 
	                  &#39;111111&#39;, 
	                  &#39;222222&#39;, 
	                  &#39;333333&#39; 
	        ), 
	        &#39;bbbbbb&#39;=> array( 
	                  &#39;111111&#39;, 
	                  &#39;222222&#39;, 
	                  &#39;333333&#39; 
	        ), 
	        &#39;cccccc&#39;         => array( 
	                  &#39;111111&#39;, 
	                  &#39;222222&#39;, 
	                  &#39;333333&#39; 
	        ), 
	  ), 
	); 
	 
	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[&#39;big&#39;]] = $arr[&#39;small&#39;]; 
	    } 
	    ***/ 
	 

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn