Simple questions about variable separator in echo

Discussion in 'PHP' started by Matt18, Aug 2, 2011.

  1. #1
    Hi

    I am learning php and have a very simple question.

    In the book I'm reading, it says that variable should be separated by commas like this: 
    echo outputitem1,outputitem2,outputitem3,...
    Code (markup):
    However in all scripts that I've been editing variable were separated by dots: 
    echo outputitem1.outputitem2.outputitem3,...
    Code (markup):
    What is the difference?

    Thanks in advance for the help!
     
    Matt18, Aug 2, 2011 IP
  2. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #2
    You can use both dots and commas to echo strings and variables with echo, however you can only use dots with print() or return etc.

    The difference is that when you use dots, every part is concatenated to a single string that will be echoed; while using commas, every part is echoed one by one without any concatenation.

    I rarely, no...I never use commas because we can't use them for return statements etc. I hope it helps.
     
    bogi, Aug 2, 2011 IP
  3. Matt18

    Matt18 Guest

    Messages:
    591
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Perfect! Thank you very much =)
     
    Matt18, Aug 2, 2011 IP
  4. andreashdk

    andreashdk Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    exactly as Bogi says, so i would advise you to only use dots as it is easier instead of remembering which to use where ;)
     
    andreashdk, Aug 2, 2011 IP