Go Back   CP Web Hosting - reseller hosting > Server Scripting > PHP
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-27-2007, 11:38 AM
Junior Member
 
Join Date: Mar 2007
Posts: 5
Default Array keys aren't quoted

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.
Reply With Quote
  #2 (permalink)  
Old 06-27-2007, 11:39 AM
Amb Amb is offline
Junior Member
 
Join Date: Apr 2007
Posts: 5
Default

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.
Reply With Quote
  #3 (permalink)  
Old 06-27-2007, 11:45 AM
Junior Member
 
Join Date: May 2007
Posts: 18
Default

If the key is stored in a variable, you do not need to use quotation marks:

$agekey = "age";
print $character[$agekey];
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:49 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0