Results 1 to 2 of 2

Thread: variable echoing

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    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.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    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
  •  



Click Here to Expand Forum to Full Width