Difference between Echo & Print ??

Discussion in 'PHP' started by gauravyadav, Oct 15, 2012.

  1. #1
    Difference between Echo & Print ??
     
    gauravyadav, Oct 15, 2012 IP
  2. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #2
    plussy, Oct 16, 2012 IP
  3. heenah

    heenah Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Quick answer is

    1) print returns true/false value whereas echo not

    2) echo is slightly faster than print

    3) echo can take more than 1 parameters when used without parentheses. print can take only one argument

    e.g. echo arg1,arg2,arg3 - valid
    echo (arg1,arg2) is invalid
     
    heenah, Oct 18, 2012 IP
  4. php_developer

    php_developer Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Print has a return value of 1 so it can be used in expressions whereas echo has a void return type.
     
    php_developer, Oct 20, 2012 IP
  5. henrycarpenter03

    henrycarpenter03 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    1. Speed (echo is slightly faster than print)
    2. Parameter (echo can take multiple parameters unlike print)
    3. Expression (print can be used as part of more complex expression where echo cannot)
     
    henrycarpenter03, Oct 20, 2012 IP
  6. EitanXOR

    EitanXOR Greenhorn

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #6
    The main difference is that print() is a function, while echo is a language construct. There are some places where PHP parser grammar won't allow a language construct, and only allows a function. But, the plus side of echo, is that language construct are faster to process than functions
     
    EitanXOR, Oct 21, 2012 IP
  7. umeedngo

    umeedngo Peon

    Messages:
    96
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Echo is Slightly faster than print and one more thing print returns the value 1 whereas echo returns nothing its return type is void.
     
    umeedngo, Oct 22, 2012 IP