0
$arr = array(array(array(array(array()))));

The above example shows an array with five dimensions.

Is there a maximum number of dimensions allowed in a PHP array? If so, what is that maximum?

FThompson
  • 28,352
  • 13
  • 60
  • 93
  • Does this help? http://stackoverflow.com/questions/9089230/multidimensional-array-size-limit-in-php – Parziphal Oct 17 '13 at 03:02
  • See: [http://stackoverflow.com/questions/467149/what-is-the-max-key-size-for-an-array-in-php][1] [1]: http://stackoverflow.com/questions/467149/what-is-the-max-key-size-for-an-array-in-php – Johnny Oct 17 '13 at 03:03
  • build a crazy loop and test it :-) –  Oct 17 '13 at 03:08
  • And possibly also relevant: [A Closer Look Into PHP Arrays: What You Don’t See](https://sheriframadan.com/2012/10/a-closer-look-into-php-arrays/) – mario Oct 17 '13 at 03:14
  • Create a custom function as defined here: http://stackoverflow.com/questions/262891/is-there-a-way-to-find-how-how-deep-a-php-array-is – foxns7 Oct 17 '13 at 03:17

2 Answers2

2

Each array level generally costs you 304 bytes (determined by checking memory usage, creating an array, then checking again), and the total amount of memory can be calculated using ini_get("memory_limit"). To get the current usage, run memory_get_usage().

On my computer:

  • ini_get("memory_limit") returns "128M", or 134217728 bytes.
  • memory_get_usage() base use is 627120

so I would expect the limit on my kit to be 439442 depth

SheetJS
  • 22,470
  • 12
  • 65
  • 75
1

It's about memory limit. Try it yourself.

$array = array();
$temp_array = &$array;
while (true)
    $temp_array = &$temp_array[0];
sectus
  • 15,605
  • 5
  • 55
  • 97