Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

WWWXXXDOCO, nu vot, WWWXXXAPC, dhcpd lease file "binding state", WWWXXXDOCO, how to setup procmail to process html2text, how to setup procmail html2text, WWWXXXAPC., XXXCNZZZ, ss4000 recovery array

Links

XODOX
Impressum

#1: array variables with or without quotes

Posted on 2006-02-22 06:22:55 by 2dogs

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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#2: Re: array variables with or without quotes

Posted on 2006-02-22 06:52:39 by Chris

> 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.

Without quotes it could be constant or defined variable:

define('variable', 'blah blah blah');

so then I can just use:

<?php
define('variable', 'blah blah blah');
echo variable;
?>

will print out:

blah blah blah

So in your case, it's checking for a defined variable called 'include'
which doesn't exist (and prints out a warning/notice).

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#3: Re: array variables with or without quotes

Posted on 2006-02-22 21:29:56 by Chuck Anderson

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#langua ge.types.array.foo-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

Report this message

#4: RE: Re: array variables with or without quotes

Posted on 2006-02-22 21:58:14 by Jason Karns

------=_NextPart_000_015C_01C637C8.C95E86C0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

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#langua ge.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


------=_NextPart_000_015C_01C637C8.C95E86C0
Content-Type: application/x-pkcs7-signature;
name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="smime.p7s"

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEH AQAAoIII9TCCAn0w
ggHmoAMCAQICECCiA6pLAuHQDGnH8XjLYicwDQYJKoZIhvcNAQEEBQAwYjEL MAkGA1UEBhMCWkEx
JTAjBgNVBAoTHFRoYXd0ZSBDb25zdWx0aW5nIChQdHkpIEx0ZC4xLDAqBgNV BAMTI1RoYXd0ZSBQ
ZXJzb25hbCBGcmVlbWFpbCBJc3N1aW5nIENBMB4XDTA1MTIyMDE2NTE1M1oX DTA2MTIyMDE2NTE1
M1owYDEOMAwGA1UEBBMFS2FybnMxDjAMBgNVBCoTBUphc29uMRQwEgYDVQQD EwtKYXNvbiBLYXJu
czEoMCYGCSqGSIb3DQEJARYZa2FybnNqQGNzZS5vaGlvLXN0YXRlLmVkdTCB nzANBgkqhkiG9w0B
AQEFAAOBjQAwgYkCgYEA9IF+hWaKqiEfwKRu3das+Lh7IvQB5RAckj8sW/0m TBRem1di+VWoKdDi
UPEe0zpcCoEvp70CtpFlFdSN94J4KBzBvLg6jPnIznCE/Nq6zsWyhyFIKJfi A96GypQ+ntJIINt1
zubKxGRTaIGVBOsl/QwihfnwimhmzogKheYZO28CAwEAAaM2MDQwJAYDVR0R BB0wG4EZa2FybnNq
QGNzZS5vaGlvLXN0YXRlLmVkdTAMBgNVHRMBAf8EAjAAMA0GCSqGSIb3DQEB BAUAA4GBAFdPDsD3
44yI6uKXQnBOxfTv7wM43PtN7Yf9BQNUaALkJIw/haeSwqvZLBt/rWfH9LOx eecaqLWQ4VAFgnG4
PbXsKebFvUXyp/D7JMNYbIiwt+J/GU3/bnio1oAEIBjxl6rVxhQurfL0RtSY iLGW+QSvVmNvHQyD
ViolxYYRrb8FMIIDLTCCApag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RlSBn7t/4u72t TSRszm00GkmaxbRk
MEsnw/FioBAlqYqlzbFEczg243UvhsKZyIRsqCux2gAAAAAAAA==

------=_NextPart_000_015C_01C637C8.C95E86C0--

Report this message

#5: Re: array variables with or without quotes

Posted on 2006-02-23 04:08:05 by 2dogs

Chuck, you are the man! I decided to reread the manual word for word but
have only gotten through Strings as of last night. Thanks for zeroing me in
on the right spot.

txs
2dogs





"Chuck Anderson" <hairtwoday@gmail.com> wrote in message
news:34.21.50685.8C9CCF34@pb1.pair.com...
> 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#langua ge.types.array.foo-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

Report this message