Forum Moderators: coopster

Message Too Old, No Replies

Maximum keys in an array?

What's the limit?

         

sawatkins

8:23 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



Is there a limit to how many keys can populate an two-dimensional array? Up to 350?

I know that seems like a lot, but, to the best of my knowledge, it has to be that way.

G

jatar_k

8:27 pm on Apr 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I also believe the number has to do with memory limits as opposed to actual elements in any given array

350 will be fine, barring you are storing 1G in each element ;)

coopster

10:35 pm on Apr 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Memory limits are one thing and/or operating system might be an issue, too. If the array has numerical indexes I imagine you might run into an integer [php.net] maximum on certain platforms.

The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed).

I also found this note on the array_pad() [php.net] function manual page:

It is possible to add most 1048576 elements at a time.

Just a couple of things to be aware of. As stated though, I don't think you'll have any issue with 350, shouldn't be an issue.

joelgreen

11:11 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



I once tested an array of about 300000 items (a kind of ip to location mapper). For some reason php (php 4.x, Windows) had problems accessing/comparing some array elements, so i decided to put data in mysql database instead.
So my advice would be to avoid using huge arrays in php.