How to determine php array dimensions (php array length)

WBOY
Release: 2016-07-25 08:55:47
Original
1623 people have browsed it
  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. ?>

复制代码


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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template