|
-
Jun 22nd, 2004, 09:34 AM
#1
Thread Starter
Frenzied Member
variable echoing
Ok, so one of the threads on here got me thinking the other day, and I want to know the correct way to do things.
Whenever I have a variable that I want to print out in the middle of an echo string, I do the following:
PHP Code:
echo "I want to print this var: " . $var . " units;
And now I've even seen the following on php.net:
PHP Code:
echo "I want to print this var: $var units";
No quotes, no indication to the processor that it's a php variable other than the dollar sign. Does it matter? Is one slower? And what's the difference between single and double quotes and when should I use either because right now the only time I use single quotes is in SQL queries in the WHERE clause.
-
Jun 22nd, 2004, 01:20 PM
#2
That is basicly the power of the double quotes:
PHP Code:
$a = 'something';
$b1 = "a=$a"; // a=something
$b2 = 'a=$a'; // a=$a
$c['key']='value';
$d1 = "c=$c[key]"; // c=value
$d2 = "c={$c['key']}"; // c=value
$d3 = 'c=$c[key]'; // c=$c[key]
Double qoutes expand variables, they are very usefull to make code more readable. There is no significant difference in performance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|