欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php數(shù)組遍歷類與用法示例

 更新時間:2019年05月24日 14:19:41   作者:a小風(fēng)車  
這篇文章主要介紹了php數(shù)組遍歷類與用法,結(jié)合實例形式分析了php基于面向?qū)ο蟮臄?shù)組遍歷、讀取操作封裝與使用技巧,需要的朋友可以參考下

本文實例講述了php數(shù)組遍歷類與用法。分享給大家供大家參考,具體如下:

<?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;

運行結(jié)果:

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

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP數(shù)組(Array)操作技巧大全》、《php排序算法總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計算法總結(jié)》、《php字符串(string)用法總結(jié)》及《PHP常用遍歷算法與技巧總結(jié)

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論