RE: [PHP] Re: array variables with or without quotes
| From: | Jason Karns | Date: | Wed, 22 Feb 2006 20:58:14 +0000 |
| Subject: | RE: [PHP] Re: array variables with or without quotes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-230908@lists.php.net to get a copy of this message | ||
I believe it is because without the quotes, it is expecting a predefined
constant. With the quotes, it is expecting an array key. This is why if you
use a word that is not defined as a constant, php will first look for it as
a constant, won't find it, then looks through the array treating it like a
key. If it is found as a constant, then the constant's value is used as the
key.
Jason
-----Original Message-----
From: Chuck Anderson [mailto:hairtwoday@gmail.com]
Sent: Wednesday, February 22, 2006 3:30 PM
To: php-general@lists.php.net
Subject: [PHP] Re: array variables with or without quotes
2dogs wrote:
>I recently encountered a situation where I had to retrieve data from a
>MYSQL database table with a field named "include". My code looked like
this:
>
>$content_result = mysql_query('SELECT * FROM calander') or
>die(mysql_error()); $content_row = mysql_fetch_array($content_result);
>if ($content_row[include])
> {go do something;}
>
>When I tried to run this, PHP treated the word -include- as a control
>structure rather than an index name. Understandable. So, I put it in
>single quotes ('include') to see what would happen and it works fine.
>But I don't understand why!
>
>What is the difference between $content_row [include] and
>$content_row['include']? I have been unable to resolve this question in
>the php manual, I need enlightenment.
>
>2dogs
>
>
http://www.php.net/manual/en/language.types.array.php#language.types.array.f
oo-bar
--
*****************************
Chuck Anderson . Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php
Attachment: [application/x-pkcs7-signature] smime.p7s
Attachment: [application/x-pkcs7-signature] smime.p7s