Is there a limit for an array in PHP?
The theoretical maximum Java array size is 2,147,483,647 elements.
Multidimensional PHP arrays can have any number of dimensions, starting from two. Two-dimensional PHP arrays contain arrays in which variables are stored.
Explanation: If the index of the array size is exceeded, the program will crash.
An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed.
Yes, there's a limit on the maximum number of elements. The hash table structure (arrays are basically wrappers around a hash table) is defined like this (PHP 5.3):
typedef struct _hashtable { uint nTableSize; uint nTableMask; uint nNumOfElements; ulong nNextFreeElement; Bucket *pInternalPointer; /* Used for element traversal */ Bucket *pListHead; Bucket *pListTail; Bucket **arBuckets; dtor_func_t pDestructor; zend_bool persistent; unsigned char nApplyCount; zend_bool bApplyProtection; #if ZEND_DEBUG int inconsistent; #endif } HashTable;
given that
typedef unsigned int uint;
the limit is the maximum size of an unsigned int (typically 2^32-1 on a 32-bit OS and on most 64-bit OS).
In practice, however, except on machines with lots of RAM and 32-bit ints, you will always hit the memory limit before this becomes an issue.
The only thing I've come across in reference to php is this from bytes.com/forum:
I don't think there is a limit on how big an array can be, but there is a limit on how much memory your script can use.
The 'memory_limit' directive in the php.ini configuration file holds the max amount of memory your scripts can consume. Try changing this, see if that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With