What's the maximum number of keys for an array in php

arrays, php

Solution

Darryl Hein,

Yeah, there isn't anything in the error logs. I even increased error reporting and still nothing relevant to print_r().

In response to Jay: I ran

echo count($lines);

and I get a result of 105,546 but still print_r() only displays 7280.

Taking Rob Walker's advice I looped over all the elements in the array and it actually contained all the results. This leads me to believe the issue is with print_r() itself instead of a limit to array size.

Another weird thing is that I tried it on one of my REHL servers and the result was as it should be. Now I don't want to blame this on Windows/IIS but there you go.

With the above in mind I think this question should be re-titled as it's no longer relevant to arrays but print_r.

Problem

I'm writing a php script where I call ``` $lines = file('base_list.txt'); ``` to break a file up into an array. The file has over 100,000 lines in it, which should be 100,000 elements in the array, but when I run ``` print_r($lines); exit; ``` the array only contains 7280 elements. So I'm curious, WTF? Is there a limit on the amount of keys an array can have? I'm running this locally on a dual-core 2.0Ghz with 2GB of RAM (Vista & IIS though); so I'm a little confused how a 4MB file could throw results like this. Edit: I have probably should have mentioned that I had previously set memory_limit to 512MB in php.ini as well.

Original source