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

后端 未结 10 1606
一整个雨季
一整个雨季 2021-02-08 03:32

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

相关标签:
10条回答
  • 2021-02-08 04:12

    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.

    0 讨论(0)
  • 2021-02-08 04:17

    I'm gonna agree with Cory. I'm thinking your PHP is probably configured default memory of 8MB, which 4MB x 2 is already more. The reason for the x2 is because you have to load the file, then to create the array you need to have the file in memory again. I'm just guessing, but that would make sense.

    Are you sure PHP isn't logging an error?

    0 讨论(0)
  • 2021-02-08 04:18

    PHP's print_r function does have limitations. However, even though you don't "see" the entire array printed, it is all there. I've struggled with this same issue when printing large data objects.

    It makes debugging difficult, if you must see the entire array you could create a loop to print every line.

    foreach ($FileLines as $Line) echo $Line;
    

    That should let you see all the lines without limitation.

    0 讨论(0)
  • 2021-02-08 04:22

    You should use count to count the number of items in an array, not print_r. What if output of this large array was aborted because of timeouts or something else? Or some bug/feature in print_r?

    0 讨论(0)
提交回复
热议问题