-
-
/** - * Author : GuoWangYunYan
- * QQ : 279861795
- * Date : 2011-6-23
- * link:www.jbuxe.com
- */
- //Set encoding
- header('Content-type: text/html; charset=utf-8');
- / /In a weird way, I used a five-dimensional array
- $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'=>array('44','55','66'),
- '222222'=>array('44' ,'55','66'),
- '333333'=>array(
- '44'=>array('77','88','99'),
- '55'=>array( '77','88','99'),
- '66'=>array('77','88','99'),
- ),
- ),
- ),
- ); p>
//Execute function
- fun($a);
-
- //The infinite classification recursion method begins
- function fun ($_info,$deep=0){
- //Judge whether it is an array
- if ( is_array($_info)){
- //foreach loop
- foreach ($_info as $key=>$val){
- //The first time before - no more each time the loop adds 4 by the way to output the key name
- echo str_repeat (' - ',$deep).$key.'
';
- //Recursively output the key value and add 4 in front each time----
- fun($val,$deep+4) ;
- }
- } else {
- //If the key value is not an array, return directly
- echo str_repeat('-', $deep) . "$val
";
- }
- }
- ?>< /p>
-
Copy code
Recursive explanation:
Recursion, as an algorithm, is widely used in programming languages. It refers to the reentrancy phenomenon caused by a function/process/subprogram calling itself directly or indirectly during operation.
Recursion is an important concept in computer science. The recursive method is an effective method in programming. Writing programs using recursion can make the program concise and clear.
If recursion is not used, the execution efficiency is relatively low.
|