What is the max key size for an array in PHP?

前端 未结 3 709
野趣味
野趣味 2020-11-28 12:41

I am generating associative arrays and the key value is a string concat of 1..n columns.

Is there a max length for keys that will come back to bite me? If so, I\'ll

3条回答
  •  死守一世寂寞
    2020-11-28 13:00

    It seems to be limited only by the script's memory limit.

    A quick test got me a key of 128mb no problem:

    ini_set('memory_limit', '1024M');
    
    $key = str_repeat('x', 1024 * 1024 * 128);
    
    $foo = array($key => $key);
    
    echo strlen(key($foo)) . "
    "; echo strlen($foo[$key]) . "
    ";

提交回复
热议问题