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?

4

2 回答 2

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

于 2013-10-17T03:37:21.033 回答
1

It's about memory limit. Try it yourself.

$array = array();
$temp_array = &$array;
while (true)
    $temp_array = &$temp_array[0];
于 2013-10-17T03:22:47.693 回答