php實現遍歷多維數組的方法
更新時間:2015年11月25日 09:29:57 作者:happy664618843
這篇文章主要介紹了php實現遍歷多維數組的方法,涉及php針對多維數組的遍歷與遞歸操作實現技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了php實現遍歷多維數組的方法。分享給大家供大家參考,具體如下:
$a=array('fruits'=>array('a'=>'orange','b'=>'grape',c=>'apple'),
'numbers'=>array(1,2,3,4,5,6),
'holes'=>array('first',5=>'second','third')
);
//第一種:
foreach($a as $list=>$things){
if(is_array($things)){
foreach($things as $newlist=>$counter){
echo "key:".$newlist."<br/>"."value:".$counter."<br/>";
}
}
}
//第二種:
function MulitarraytoSingle($array){
$temp=array();
if(is_array($array)){
foreach ($array as $key=>$value )
{
if(is_array($value)){
MulitarraytoSingle($value);
}
else{
$temp[]=$value;
}
}
}
}
希望本文所述對大家php程序設計有所幫助。
相關文章
PHP5下$_SERVER變量不再受magic_quotes_gpc保護的彌補方法
在php5的環(huán)境中我們的$_SERVER變量將不再受magic_quotes_gpc的保護,至于程序該如何加強自己的安全性,下面我們總結了怎么保護php中的cookie,get,post,files數據哦,有需要的朋友可參考一下2012-10-10

