本文實例講述了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;
運(yùn)行結(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è)計有所幫助。
標(biāo)簽:巴彥淖爾 重慶 臨沂 銅陵 麗江 十堰 衡陽 鷹潭
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《php數(shù)組遍歷類與用法示例》,本文關(guān)鍵詞 php,數(shù)組,遍歷,類,與,用法,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。