What is difference between print and echo

Discussion in 'PHP' started by osho3, Jun 13, 2010.

  1. #1
    What is difference between print and echo
     
    osho3, Jun 13, 2010 IP
  2. Scripts man

    Scripts man Guest

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    really i don't know
    but i think its have the same usefull
     
    Scripts man, Jun 13, 2010 IP
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  5. seminyak

    seminyak Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i think u just need to learning a basic tutorial
     
    seminyak, Jun 14, 2010 IP
  6. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #6
    print is a function (i think)
    while echo is a macro..
     
    gapz101, Jun 14, 2010 IP
  7. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #7
    No - they are both language constructs.
     
    lukeg32, Jun 15, 2010 IP
  8. sijumpk

    sijumpk Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    There is a slight difference between print and echo which would depend on how you want to use the outcome. Using the print method can return a true/false value. This may be helpful during a script execution of somesort. Echo does not return a value, but has been considered as a faster executed command.
     
    sijumpk, Jun 15, 2010 IP
  9. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #9
    Actually, No - print does not return true or false
     
    lukeg32, Jun 15, 2010 IP
  10. sijumpk

    sijumpk Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Why are you saying "print does not return true or false" ? Please try.

    <?php
    $var = print "Hello";
    echo "<br>";
    echo $var;
    ?>
     
    sijumpk, Jun 15, 2010 IP
  11. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #11
    lukeg32, Jun 15, 2010 IP
  12. sijumpk

    sijumpk Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Thats a funny answer, in php TRUE is 1 but you just misunderstood that it will return the string "true", but am saying about true and false which are booleans. If you still have doubt please refer the page http://php.net/manual/en/language.types.boolean.php or see the out put of the code

    <?php
    echo true;
    ?>
     
    sijumpk, Jun 15, 2010 IP
  13. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #13
    Again, incorrect.

    (int) 1 is NOT the same as (boolean) true.

    <?php
    $int = 1;
    $bool = TRUE;
    
    if($int === $bool) print "they match\n";
    else print "they do not match\n";
    ?>
    PHP:
    OUTPUT: they do not match
     
    lukeg32, Jun 15, 2010 IP
  14. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #14
    gapz101, Jun 15, 2010 IP
  15. sijumpk

    sijumpk Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Sorry, I don't think you can only understand in that way. I think you are only trying to see holes in a dougnut, as the topic is one and you are saying something. Who is saying that integer 1 is same as true in both data type and value. Almost everyone knows they are of two types but of same value. if you want to check they are of same value please try

    <?php
    $int = 1;
    $bool = TRUE;

    if($int == $bool) print "they match\n";
    else print "they do not match\n";
    ?>

    if we are using the return value of print, I don't think it will return (int) 1 and (boolean) TRUE in different cases just true or false thats it. Then what do you think print will return if you think it will neither return true or false as in http://forums.digitalpoint.com/showthread.php?t=1836834&p=14391629#post14391629.
     
    sijumpk, Jun 15, 2010 IP
  16. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #16
    Once again, it does NOT return true or false. It returns 1.There is no condition to this.
     
    lukeg32, Jun 15, 2010 IP
  17. sijumpk

    sijumpk Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Yes, you are right print is returning integer 1 not a boolean value
     
    sijumpk, Jun 15, 2010 IP
  18. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #18
    Oops!
    print and echo are same like <b> and <strong>

    But echo is much faster than print :) [Google as PHP Echo Vs Print to know more ]
     
    Last edited: Jun 15, 2010
    roopajyothi, Jun 15, 2010 IP
  19. aeroz1

    aeroz1 Active Member

    Messages:
    492
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #19
    There is a slight difference between print and echo which would depend on how you want to use the outcome. Using the print method can return a true/false value. This may be helpful during a script execution of somesort. Echo does not return a value, but has been considered as a faster executed command. All this can get into a rather complicated discussion, so for now, you can just use whichever one you prefer.
     
    aeroz1, Jun 15, 2010 IP
  20. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #20
    Right thats what i am talking about!
    Print can be used at particular places but using echo you can do that same printing job(In Browser)
     
    roopajyothi, Jun 15, 2010 IP