/    Sign up×
Community /Pin to ProfileBookmark

When to use quotes

I have a question about quotes. When should I quote the array key and how am I supposed to do that in a SQL command?

[code=php]
$query=”Update Column
Set Error=TRUE
Where llama[black]=alpaca”
[/code]

Also, more verification on when exactly to use doubles and singles. I understand the variables in doubles vs singles but otherwise I still haven’t grasped it yet. I’m sorry about how vague that is, so you don’t have to answer it. I’d say I’m a beginner-intermediate level PHP programmer, but I just am still confused on this.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 15.2006 — Start by reading about the string type: http://www.php.net/manual/en/language.types.string.php

Also see the "Why is $foo[bar] wrong?" section of this page: http://www.php.net/manual/en/language.types.array.php

Once you've completed that assignment, there will be a short quiz. ?
Copy linkTweet thisAlerts:
@NogDogSep 15.2006 — PS: One possible way to do your query definition (assuming $llama is an array and 'alpaca' is a literal value you want to match):
[code=php]
$query="Update Column
Set Error=TRUE
Where {$llama['black']}='alpaca'";
[/code]
Copy linkTweet thisAlerts:
@chesemonkylomaauthorSep 15.2006 — so the whole array variable doesnt have to be in quotes, just the key?
Copy linkTweet thisAlerts:
@chesemonkylomaauthorSep 15.2006 — or am i missing something
Copy linkTweet thisAlerts:
@NogDogSep 15.2006 — so the whole array variable doesnt have to be in quotes, just the key?[/QUOTE]
Correct, [i]if[/i] you are using a string literal as the key. If you are using a [url=http://www.php.net/define]define()'d constant[/url] or a variable, then the key would not be quoted. (Technically, you [i]could[/i] double-quote a varialbe key, such as [b]$array["$key"][/b], but that's unnecessary and will add a tiny bit to the processing time.)
Copy linkTweet thisAlerts:
@chesemonkylomaauthorSep 15.2006 — thank you!
×

Success!

Help @chesemonkyloma spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...