The keys in an associative array are strings, but in its default error reporting state the engine won’t complain if array keys aren’t quoted.
Omitting quotation marks for array keys is poor practice, however. If you use unquoted strings as keys and your error reporting is set to a higher-than-standard level, the engine will complain every time such an element is met. Even worse, if an unquoted array key coincides with a constant, the value of the constant will be substituted for the key as typed.
If the key is stored in a variable, you do not need to use quotation marks:
$agekey = “age”;
Leave a Reply
You must be logged in to post a comment.