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

php无限级分类程序

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-25 16:43:25
Original
1315 people have browsed it

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template