Home > php教程 > php手册 > PHP判断数组是一维二维或几维

PHP判断数组是一维二维或几维

WBOY
Release: 2016-06-13 09:37:00
Original
1100 people have browsed it

   //可以判断是一维的,还是二维的,或是几维的数组:

  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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template