PHP判斷數組是一維二維或幾維實例

導語:PHP中比較要的一個知識點就是數組了,你對數組的.認識有多少呢?下面的是本站小編爲大家蒐集的PHP判斷數組是一維二維或幾維實例,供大家參考。

PHP判斷數組是一維二維或幾維實例

//可以判斷是一維的,還是二維的,或是幾維的數組:

function getmaxdim($arr){

if(!is_array($arr)){

return 0;

}else{

$dimension = 0;

foreach($arr as $item1)

{

$t1=$this->getmaxdim($item1);

if($t1>$dimension){$dimension = $t1;}

}

return $dimension+1;

}

}

//驗證過可以使用.

//測試

$arr=array('yiyi'=>1212,'haha'=>array('heihei'=>array(array("a")),"b"));

echo getmaxdim($arr);

//結果 4