Difference between echo,print and die

Author Topic: Difference between echo,print and die  (Read 5145 times)

Offline VinilTopic starter

  • Trade Count: (0)
  • Sr. Member
  • ****
  • Thank You 97
  • Posts: 301
  • Karma: 13
  • Gender: Male
  • I can and I Will
    • Boaters Directory
Difference between echo,print and die
« on: 02-08-2012, 00:00:46 »
Do you know differences between echo,print and die?let me know as i have seen all of these works the same but in different manner .I want to know that manner in which all theses works


Offline sam

  • Trade Count: (0)
  • Semi-Newbie
  • *
  • Thank You 0
  • Posts: 20
  • Karma: 3
  • Gender: Male
    • anyquestion.webvertex.co.in
Re: Difference between echo,print and die
« Reply #1 on: 02-08-2012, 23:04:24 »
when u use print(),a value of 1 or 0 will be returned upon
success or failure of the the print command.where as echo()
just does what its told without letting u know whether  or
not it worked properly.anyquestion.webvertex.co.in

Offline VinilTopic starter

  • Trade Count: (0)
  • Sr. Member
  • ****
  • Thank You 97
  • Posts: 301
  • Karma: 13
  • Gender: Male
  • I can and I Will
    • Boaters Directory
Re: Difference between echo,print and die
« Reply #2 on: 02-08-2012, 23:05:44 »
thanks for the response but may i know  the function of die() in php?

Offline sam

  • Trade Count: (0)
  • Semi-Newbie
  • *
  • Thank You 0
  • Posts: 20
  • Karma: 3
  • Gender: Male
    • anyquestion.webvertex.co.in
Re: Difference between echo,print and die
« Reply #3 on: 02-08-2012, 23:15:40 »
the die() function in php
prints a message and exits the current script.

example

$c=mysql_connect('host','username','pass') or die();

if the mysql connection is unsuccessful then this will die

Can you tell me how to add signature in the forums

like you did
i just want to add my site link
Thanks

Offline VinilTopic starter

  • Trade Count: (0)
  • Sr. Member
  • ****
  • Thank You 97
  • Posts: 301
  • Karma: 13
  • Gender: Male
  • I can and I Will
    • Boaters Directory
Re: Difference between echo,print and die
« Reply #4 on: 02-08-2012, 23:19:13 »
http://www.seomastering.com/seo-forum/seo_forum_discussion/forum_rules/
Read this


Offline sam

  • Trade Count: (0)
  • Semi-Newbie
  • *
  • Thank You 0
  • Posts: 20
  • Karma: 3
  • Gender: Male
    • anyquestion.webvertex.co.in
Re: Difference between echo,print and die
« Reply #5 on: 02-08-2012, 23:24:02 »
ok thanks

Offline nancyfromafrica

  • Trade Count: (0)
  • Semi-Newbie
  • *
  • Thank You 0
  • Posts: 19
  • Karma: 0
  • Gender: Female
  • i love my iPhone
Re: Difference between echo,print and die
« Reply #6 on: 03-05-2013, 05:57:31 »


        Speed. There is a difference between the two, but speed-wise it should be irrelevant which one you use. echo is marginally faster since it doesn't set a return value if you really want to get down to the nitty gritty.

        Expression. print() behaves like a function in that you can do: $ret = print "Hello World"; And $ret will be

        That means that print can be used as part of a more complex expression where echo cannot. An example from the PHP Manual:

        $b ? print "true" : print "false";

    print is also part of the precedence table which it needs to be if it is to be used within a complex expression. It is just about at the bottom of the precedence list though. Only "," AND, OR and XOR are lower.

        Parameter(s). The grammar is: echo expression [, expression[, expression] ... ] But echo ( expression, expression ) is not valid. This would be valid: echo ("howdy"),("partner"); the same as: echo "howdy","partner";
        (Putting the brackets in that simple example serves no purpose since there is no operator precedence issue with a single term like that.)

    So, echo without parentheses can take multiple parameters, which get concatenated:

    echo "and a ", 1, 2, 3; // comma-separated without parentheses
    echo ("and a 123"); // just one parameter with parentheses

    print() can only take one parameter:

    print ("and a 123"); print "and a 123";

 

Related Topics

  Subject / Started by Replies Last post
23 Replies
4963 Views
Last post 02-04-2012, 13:06:47
by dany
6 Replies
2373 Views
Last post 10-24-2011, 00:30:13
by Hogward
0 Replies
1051 Views
Last post 10-25-2011, 00:21:27
by manvbf
24 Replies
9781 Views
Last post 12-04-2016, 23:34:48
by annarichart
34 Replies
16389 Views
Last post 03-25-2014, 06:13:10
by parijatziw