Results 1 to 2 of 2
Dec 4, 2002, 10:35 #1
- Join Date
- Jul 2002
- Along the Wasatch Fault line.
- 0 Post(s)
- 0 Thread(s)
$array[key], $array['key'], $array["key"] ?
I am wondering just what the differences between the following formats are:
How does each affect performance?
What are the advantages/disadvantages between each (if there are any)?John
Dec 4, 2002, 10:58 #2
They are functionally identical when mere referencing an array key name, but if you were to use a variable:
$array['$key'] : Would pass a literal string '$key'
$array["$key"] : Would pass the value of $key
If you were to use:
Then PHP will first search for a defined constant named "key", if it doesnt find this, then it will regard it as a key name. If you were to set your error reporting to E_ALL you would see the results of using arrays in this fashion, and its to be avoided as it results in a loss of performance.
Similar could be said for $array["$key"], as PHP will expect a string, but will also parse that string for variables. Another performance hit. Just use $array[ $key ].THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
OVER YOUR DOG. <-- MediaWiki installation guide