Forum Moderators: coopster
$myArray[123] = "my value" ;
$val = $myArray[123] ;
$myArray["123"] = "my value" ;
$val = $myArray["123"] ;
define("C123", "my value") ;
$val = C123 ;
Is using a integer key increase performance while retrieving a value?
When it's possible, is using "define()" faster?
Are they all the same?
There are no different indexed and associative array types in PHP; there is only one array type, which can both contain integer and string indices.
anyway, i haven't found a speed comparison chart about that and it could be cool if someone will run a test on that ;).
Addition:
Only scalar data (boolean, integer, float and string) can be contained in constants.so define is out of range for your speed comparison.
There are no different indexed and associative array types in PHP; there is only one array type, which can both contain integer and string indices
I think a integer key could potentially be faster than a string key because it may then be used internally as a "real" array.. Compilator (or "interpreter", whatever) could jump immediately to the given index. Using a associative array, with a string key, the compilator would have to hash the key first to find the associated value. And as you say, the longer the string is, the longer it'll take. I guess.
But hey, that's just hypothesis.
so define is out of range for your speed comparison.
What I'm currently developing is a multilingual application (by the way sorry if my english is not perfect). Depending of the language the user chooses, an appropriated include is done.
And I wonder how to include the languages specific strings in the fastest way.
But you're right: I should do some benchmarks testing...
But I wanted to ask you guys first! ;-)
Thanks for your help.