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

php无限级分类程序

WBOY
WBOYOriginal
2016-05-25 16:43:251278browse

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

<?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;]; 
	    } 
	    ***/ 
	 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn