Home  >  Article  >  Backend Development  >  How to determine php array dimensions (php array length)

How to determine php array dimensions (php array length)

WBOY
WBOYOriginal
2016-07-25 08:55:471626browse
  1. /**

  2. * Return the dimensions of the array
  3. * @param [type] $arr [description]
  4. * @return [type] [description]
  5. */ bbs.it-home.org
  6. function arrayLevel($arr){
  7. $al = array(0);
  8. function aL($arr,&$al,$level=0){
  9. if(is_array($arr)){
  10. $level++;
  11. $al[] = $level;
  12. foreach($arr as $v){
  13. aL($v,$al,$level);
  14. }
  15. }
  16. }
  17. aL($arr,$al);
  18. return max($al);
  19. }

  20. $arr = array(

  21. '0'=>'0',
  22. );

  23. echo arrayLevel($arr);

  24. ?>

复制代码


Statement:
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