2016-04-25 24 views
5

我尝试使用PHP创建数组。数组的维数是26000 x 26000.是否有可能使数组变大?我已经尽量让同尺寸10000×10000,但该方案的阵列一直告诉我:如何制作使用PHP的大数组(26000 x 26000)?

Fatal error: Out of memory (allocated 1886388224) (tried to allocate 24 bytes) in C:\xampp\htdocs\matrix\index.php on line 24

我有8GB的内存,我已经设置memory_limit的与-1(Apache的配置)的php.ini。构建阵列的代码是这样的:

function zeros($rowCount, $colCount) 
{ 
    $matrix = array(); 
    for ($rowIndx=0; $rowIndx<$rowCount; $rowIndx++) 
    { 
     $matrix[] = array(); 
     for($colIndx=0; $colIndx<$colCount; $colIndx++) 
     { 
      $matrix[$rowIndx][$colIndx]=0; 
     } 
     var_dump(memory_get_usage()); 
    } 
    return $matrix; 
} 

$matrix = zeros(25000,25000); 

我也已经尝试使用SplFixedArray,但结果是相同的。 请帮助我,谢谢! :)

+5

我想知道你的使用情况是什么这样的大型阵列。是否有可能,是的,尽管我希望不久之后你会需要更多的记忆,但这是否有必要。 –

+2

如果您使用直接数字索引,并且事先知道数组的维数,为什么不考虑[SPLFixedArray](http://nl3.php.net/manual/en/class.splfixedarray.php)而不是 –

+7

我测试从100,100到600,600:memoryUsage /arrayElements≈200字节,所以在你的情况下,它会需要25000 * 25000 * 200字节≈100GB –

回答

-1

您可以使用这段代码也

$mon = range(1, 26000); 
    for($i=0;$i<=25999;$i++){ 
     $mon[$i] = range(1, 26000); 
    }