• PHP无限遍历数组


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无限数组遍历</title>
    </head>

    <body>

    <?php


     //生成从1到100的数组的值
     $arr=array();
     echo "<pre>"; //按原格式显示
     for ($i=0;$i<=99;$i++){
       $arr[$i]=($i+1);
     }
     print_r($arr);
     echo "</pre>";

     //无限遍历数组
     $a1=array("a","b","c"); //一维数组
     $a2=array(array(21,3,6),array("a","b","c")); //二维数组
     $a3=array(array(array(5,55),4,444),2,7,6,8,array("w","d",array(3,2,"a"),"s")); //多维不规则数组
     
     function fun($a){
          foreach($a as $val){
         if (is_array($val)){ //如果键值是数组,则进行函数递归调用
        fun($val);
      }
      else{ // 如果键值是数值,则进行输出
        echo "$val<br />";
      } //end if
       } //end foreach
     } //end fun
     
     fun($a3);

    ?>

    </body>
    </html>

  • 相关阅读:
    [CF1365D] Solve The Maze
    [CF478C] Table Decorations
    [CF466D] Increase Sequence
    [CF449D] Jzzhu and Numbers
    [CF507E] Breaking Good
    [CF337D] Book of Evil
    [CF1253E] Antenna Coverage
    VMware 在 Win10 下开机后死机的解决方案
    [CF1009F] Dominant Indices
    [CF1037E] Trips
  • 原文地址:https://www.cnblogs.com/wicub/p/2886734.html
Copyright © 2020-2023  润新知