I’m wondering if experienced programmers among you can tell me which is better to use between ’ and ". When I started, I read somewhere that the choice is mainly up to my own personal style/taste, and it really doesn’t make any difference between ’ and ", so I made a choice to use double quote.
But now, I’m taking a baby step towards learning PHP and MySQL (so that I may be able to get my Corona apps to talk to database), and I read we can place simple variables inside a double-quoted string. Single-quoted string will literally send what’s inside the quote, while double-quoted string will be evaluated first and the result of the evaluation would be spat out. (Confusing, eh?)
So, I thought, if I want to be extra clear as to my intention, I thought I should just go with single-quote (it will spit out literally what’s inside the quote), rather than taking a chance with double-quote, which may, if coded without care, could spit out unintended result.
But then, what confuses me is this book (“PHP and MySQL Web Development” by Luke Welling and Laura Thomson) seems to use both single quote and double quote. Sample code for html uses double quote, while sample code for php uses single quote. Why? Why? Why?
I mean, I can replace all double quotes from the html sample code with single quotes, and it works just fine. (But if you swap double quotes to single quotes from php code, it can easily cause a problem because of the evaluation thingy mentioned above.) So… why didn’t they, the authors, choose single quote consistently for both html and php?
Is it advisable to use double quote for html while single quote is better for php? Is there a hidden wisdom that I should be aware of?
Naomi
Edit: And… now I see sample php codes that mix up double and single quotes (and they don’t even need to use double quotes because no evaluation/interpolation are required in these samples.) Maybe there’s no magic rule. Maybe it’s just a result of more than one person writing the code with different style/taste. I just don’t know… but I suppose I just have to forge ahead and establish my own rules. *sigh* [import]uid: 67217 topic_id: 29138 reply_id: 329138[/import]