Re: quick question
| From: | Erik Price | Date: | Fri, 11 Jan 2002 22:08:34 +0000 |
| Subject: | Re: quick question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-80245@lists.php.net to get a copy of this message | ||
It seems that you are saying that not using quotes is bad (first), but then later you show that omitting the quotes does not result in an error.
Or are you saying that the quotes can be omitted if the array element is being used in a string (between quotes), but generally the quotes around the constant are needed to perform non-string operations?
Thank you,
Erik
On Friday, January 11, 2002, at 01:06 PM, Philip Olson wrote:
On a related note, outside of strings one should always surround keys with quotes, so: $arr = array('a' => 'apple', 'b' => 'banana'); print $arr['a']; // apple print $arr[a]; // apple BUT this is bad Without the quotes is bad because PHP first: a) looks for the constant named 'a' b) if constant 'a' is not found, an error of type$sql = "SELECT * FROM tablename WHERE tablename.column=$_GET['criteria_integer']"; but unfortunately, this isn't working.E_NOTICE is thrown.So, let's do this: define('a','b'); print $arr['a']; // apple print $arr[a]; // banana (no error) Because constants are not looked for within strings, the following is appropriate:print "an $arr[a]"; // an appleAs are: print "an {$arr['a']}"; // an apple print "an ". $arr['a']; // an apple Anyway, maybe that helps explain a few things :) Regards, Philip Olson