Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 75321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:29:52+00:00 2026-05-10T20:29:52+00:00

A PHP array can have arrays for its elements. And those arrays can have

  • 0

A PHP array can have arrays for its elements. And those arrays can have arrays and so on and so forth. Is there a way to find out the maximum nesting that exists in a PHP array? An example would be a function that returns 1 if the initial array does not have arrays as elements, 2 if at least one element is an array, and so on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:29:53+00:00Added an answer on May 10, 2026 at 8:29 pm

    This should do it:

    <?php  function array_depth(array $array) {     $max_depth = 1;      foreach ($array as $value) {         if (is_array($value)) {             $depth = array_depth($value) + 1;              if ($depth > $max_depth) {                 $max_depth = $depth;             }         }     }      return $max_depth; }  ?> 

    Edit: Tested it very quickly and it appears to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer IMHO it's bad practice to have unit tests create or… May 11, 2026 at 11:45 am
  • added an answer I think you've got the most important bits already. As… May 11, 2026 at 11:45 am
  • added an answer You say the file is actually empty. The first line… May 11, 2026 at 11:45 am

Related Questions

A PHP array can have arrays for its elements. And those arrays can have
Say I have an array of strings in a php array called $foo with
I have an array in PHP which holds a bunch of unix timestamps. As
I'm working on a program that uses PHP's internal array pointers to iterate along
In php, I often need to map a variable using an array ... but
<?php function toconv(string) { $gogo = array(a => b,cd => e); $string = str_replace(
Which is better to use in PHP, a 2D array or a class? I've
I have the following arrays in PHP (okay they are a bit bigger but
I'm finding myself doing a lot of things with associative arrays in PHP. I
Situation: A PHP application with multiple installable modules creates a new table in database

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.