zoukankan      html  css  js  c++  java
  • 多维数组的变异遍历

    <?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
  • 相关阅读:
    程序的了解
    Oracle VM VirtualBox虚拟网卡消失解决方法
    YARN 运维、巡检、监控、调优、排障
    HDFS巡检、监控、调优、排障
    Windows CMD命令大全
    [HDU]6356 Glad You Came(ST表)
    [BZOJ] 1019 [SHOI2008]汉诺塔
    树上叶子之间点对距离平方和
    [BZOJ]1026[SCOI2009]windy数
    [计蒜客]A1542 The Maximum Unreachable Node Set
  • 原文地址:https://www.cnblogs.com/love1226/p/4433704.html
Copyright © 2011-2022 走看看