What is difference between print and echo

Discussion in 'PHP' started by Hussy, Jul 1, 2010.

  1. #1
    hi...friend,

    any one tell me

    What is difference between print and echo





    thanks:rolleyes:
     
    Hussy, Jul 1, 2010 IP
  2. getquicksolution

    getquicksolution Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    echo is faster than print.
    print returns true or false but echo does not.
     
    getquicksolution, Jul 1, 2010 IP
  3. Triggs

    Triggs Active Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #3
    Well, according to the documentation, it returns 1 always.
    I believe print() is meant to be used as a function like this;

    
    while(print('string')) { }
    
    PHP:
    Anyways, echo is faster because there's no return value. I'm sure the difference is minimal.
     
    Triggs, Jul 1, 2010 IP
  4. TheDataPlanet.com

    TheDataPlanet.com Well-Known Member

    Messages:
    503
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #4
    echo is a language-native feature while print() is implemented as a function.
     
    TheDataPlanet.com, Jul 1, 2010 IP
  5. Triggs

    Triggs Active Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #5
    print is technically not a function either, just like echo.

    Just clarifying.
     
    Triggs, Jul 1, 2010 IP
  6. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #6
    It depends on how you are using it.

    Tested across a high end VPS, dedicated server, local server (debian, ubuntu, centos) using 50k iterations of a string print is actually faster.

    If you are concat'ing strings, echo is far far slower.... However, if you use comma seperated values as you are meant too (but no-one does :|) then echo is the faster of the two.....

    Buy saying "echo is faster than print" is not, nowadays, correct [in the above setups].

    Of course, it is faster to type since its one less character..... :)
     
    lukeg32, Jul 1, 2010 IP
  7. Triggs

    Triggs Active Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #7
    Well, the speed difference wasn't significant I assume?
    Anyways, thanks for the info.
     
    Triggs, Jul 1, 2010 IP
  8. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #8
    No, you are right - even on such as redundant test as i mentioned there wasnt much in it so for production code its barely measurable.
     
    lukeg32, Jul 1, 2010 IP
  9. webal

    webal Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    In all actuality, Echo and Print differ based on how they are structured. Print returns a value much like a normal function would. But despite common belief, Print is not a function, as we can see by the fact that it doesn’t require parenthesis to work (Not to be confused with Printf). Print and Echo are actually both called language constructs, although this isn’t to say that we can’t make Print act like a function.
     
    webal, Jul 3, 2010 IP
  10. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #10
    depending upon our requirement we have to use them..., echo will never returns any value so for just print statements we can use if..,print for others....!!
     
    strgraphics, Jul 3, 2010 IP