码迷,mamicode.com
首页 > 编程语言 > 详细

多维数组的变异遍历

时间:2015-04-17 00:59:57      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

<?php
02 /*
03 *  -------------------------------------------------
04 *   Author : nowamagic
05 *   Url    : www.nowamagic.net
06 *   Date   : 2011-03-09
07 *  -------------------------------------------------
08 */
09 function arr_foreach ($arr)
10 {
11     if (!is_array ($arr))
12     {
13         return false;
14     }
15      
16     foreach ($arr as $key => $val )
17     {
18         if (is_array ($val))
19         {
20             arr_foreach ($val);
21         }
22         else
23         {
24             echo $val.‘<br/>‘;
25         }
26     }
27 }
28  
29 $arr1 = array (1=>array(11,12,13,14=>array(141,142)),2,3,4,5);
30  
31 echo ‘<pre>‘;
32 print_r($arr1);
33 echo ‘<pre>‘;
34  
35 arr_foreach ($arr1);
36 ?>

程序运行结果为:

01 Array
02 (
03     [1] => Array
04         (
05             [0] => 11
06             [1] => 12
07             [2] => 13
08             [14] => Array
09                 (
10                     [0] => 141
11                     [1] => 142
12                 )
13  
14         )
15  
16     [2] => 2
17     [3] => 3
18     [4] => 4
19     [5] => 5
20 )
21 11
22 12
23 13
24 141
25 142
26 2
27 3
28 4
29 5

多维数组的变异遍历

标签:

原文地址:http://www.cnblogs.com/love1226/p/4433704.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!