tags:

views:

2537

answers:

2

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 probably stop and do it differently.

+3  A: 

There is no practical limit to string size in PHP. According to the manual:

Note: It is no problem for a string to become very large. PHP imposes no boundary on the size of a string; the only limit is the available memory of the computer on which PHP is running.

It is safe to assume that this would apply to using strings as keys in arrays as well, but depending on how PHP handles its lookups, you may notice a performance hit as strings get larger.

Lusid
+8  A: 

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)) . "<br>";
echo strlen($foo[$key]) . "<br>";
Greg
yikes! well I certainly don't have to worry about my keys going slightly over 255 chars then.
thomasrutter