PHP implode limit bug?

2019-08-06 01:57发布

问题:

I've got a script that creates an array with around 40,000 entries, PHP arrays have no limit except the memory of the server...

However the PHP function implode() simply does not output anything, when trying to implode an array of around 40,000 entries into a string. Each array entry has about a sentence worth of a-Z characters. No memory errors, no errors at all!

Can anyone confirm this?

I'm not sure its possible to post examples!

EDIT (2013-06-03):

I can confirm that the PHP memory limit was set to -1 and PHP errors were to to E_ALL. There where no errors and simply no output. This seems to be an bug with PHP of some sort.

I was using echo implode("<br>\n", $myLogArr); with did not error or output anything, I've mananage to get the correct expected result by using foreach ($myLogArr as $line) echo $line."<br>\n";

回答1:

The following works just fine - with 50,000 entries.

<?php
$arr = array();
for ($i = 0; $i < 50000; $i++) {
    $arr[] = str_shuffle('This sentance is of average length, which The Internet says is about 14.2 words.');
}
echo implode(PHP_EOL, $arr);

I would suggest increasing error_reporting and attempting to debug this further.

Anthony.



回答2:

memory_limit to -1 and then execute your script in try catch block



回答3:

$string = str_repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,",1000000);
$array = explode(",", $string);
var_dump(sizeof($array), strlen(implode(",", $array)));

outputs:

int 1000001
int 53000000

OP, can you please show your code?