前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >php数组遍历类与用法示例

php数组遍历类与用法示例

作者头像
砸漏
发布2020-10-21 10:07:13
4740
发布2020-10-21 10:07:13
举报
文章被收录于专栏:恩蓝脚本

本文实例讲述了php数组遍历类与用法。分享给大家供大家参考,具体如下:

代码语言:javascript
复制
<?php
  class scanArray{
    public $arr;
    public $where;
    private $str;
    public function scan($arr,$where="array"){
      $this- arr = $arr;
      $this- where = $where;
      foreach($this- arr as $k= $v){
        if(is_array($v)){
          $this- where = ($this- where)."[{$k}]";
          $this- scan($v,$this- where);
        }else{
          $this- str .= $this- where."[{$k}]=".$v.'<br / ';
        }
      }
      return $this- str;
    }
    function __destruct(){
      unset($this- arr);
      unset($this- where);
    }
  }
  $a = array('g'= "a",'vv'= array("b"= "b","l"= "c","xx"= array("e","g")));
  $ah = new scanArray();
  $b = $ah- scan($a);
  echo $b;

运行结果:

array[g]=a array[vv][b]=b array[vv][l]=c array[vv][xx][0]=e array[vv][xx][1]=g

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档