What is the difference between echo and print?

If anyboyd knows, do tell me.
waiting for your prompt response.

Showing Answers 1 - 75 of 112 Answers

Venu Gopal.M

  • Sep 28th, 2006
 

Hi,

echo is a construct.echo takes multiple parameters

print is also a construct but print does not take multiple parameters

  Was this answer useful?  Yes

Ramesh

  • Oct 4th, 2006
 

Hi,

echo :-

 - Is a command only.

 - Faster than Print.

print

 -

  Was this answer useful?  Yes

Ramesh

  • Oct 4th, 2006
 

Hi,

echo:-

 - Is a command only.

 - Faster than print

print:-

 - Is a function.

 - It will return true(1) or false(0) or some values.

  Was this answer useful?  Yes

Mahendra Choudhary

  • Oct 12th, 2006
 

Main difference between echo() and print() is that echo is just an statement not a function and doesn't return's value or it just prints a value whereas print() is an function which  prints a value and also it returns value.

  Was this answer useful?  Yes

rashmi

  • Nov 2nd, 2006
 

echo is a statement and print is a function.

  Was this answer useful?  Yes

Bhupal

  • Nov 4th, 2006
 

Echo and Print are used for the same functionality printing of data.But there is echo is not a function we cannot pass arguments ,where as print is a function we can pass arguments .Thank you,Bye.

  Was this answer useful?  Yes

anas

  • Nov 9th, 2006
 

hi .i am anas.i am also preparing for PHP.basically diff. of echo and print is echo have multiple arguments and in print function have only one argument.

  Was this answer useful?  Yes

Mohamed

  • Dec 13th, 2006
 

echo is a statement an does not return valueprint is a function and returns value

  Was this answer useful?  Yes

ankita

  • Dec 15th, 2006
 

print can be used as part of a more complex expression where echo cannot.echo is marginally faster since it doesn't set a return value.

  Was this answer useful?  Yes

Raj

  • Dec 21st, 2006
 

echo : just output the content

print : it returns true for successful  output and false for unsuccessful

Bhumita

  • Dec 22nd, 2006
 

Well I have found 3 major differences between echo and print:

Echo:

1) Does not return value.

2) Faster than 'print'.

3) Can take multiple arguments.

Print:

1) It returns value.

2) Slower than 'echo'.

3) Cannot take multiple arguments.

Anand

  • Dec 28th, 2006
 

print function always returns 1.

echo statement will not return anything.

u can execute echo "Anand","mohan"; but not print("Anand","mohan"); or print"Anand","mohan";

Thanks

Anand

  Was this answer useful?  Yes

bhoomika

  • Feb 5th, 2007
 

print is a function and returns true or false value where as echo is a command only...

  Was this answer useful?  Yes

hari krishnan

  • Feb 16th, 2007
 

echo() can take multiple expressions,Print cannot take multiple expressions.echo has the slight performance advantage because it doesn't have a return value.True, echo is a little bit faster

  Was this answer useful?  Yes

geek_sport

  • May 31st, 2008
 

Here is the complete detailed explanation. The third point is the most important.

1. 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.

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

And $ret will be 1. 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.

3. 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";

  Was this answer useful?  Yes

sheeku

  • Mar 6th, 2009
 

The major differences between print and echo are:
1) echo is a language construct while print is a function
2) echo can take multiple parameters while print can't take multiple parameters
3) echo just outputs the contents to screen while print returns true on successful output and false if enable to output.
In this sense we usually says that print returns value while echo don't
4) echo is faster
than print in execution because it does not return values.

  Was this answer useful?  Yes

You are unlikely to ever want to know this, however the difference is that print will return a value to let you know if the statement worked or not, whereas trying the same thing with echo will result in error:

<?php
echo "Please don't make me say it... n";
$you = print "Hello World!n";
echo "Returning $you"; //Returning 1, assuming the print worked
?>

  Was this answer useful?  Yes

Joni Rajput

  • May 12th, 2011
 

1. echo allows more than one parameters using coma operator, while print does not allow.
2.  echo is slightly faster than print.
3. echo does not return any value , while print returns.

  Was this answer useful?  Yes

Jim Tyson

  • May 21st, 2011
 

One is a function the other a statement.  The function 


print();

returns a Boolean value and has a side effect (it displays the value of it's argument).  The statement

echo "";

has a side effect but is not evaluated and returns no value.  

In at least some tests echo has been clocked as marginally faster.   This means that you can test the outcome of print() but you cannot directly test the success or otherwise of echo.

  Was this answer useful?  Yes

Both are output statements, Both are language constructs, print returns a value. require parenthesis. echo accept multiply argument, echo give u same output, echo doesn't return anything and it is like a tag print always return a integer value 1.

  Was this answer useful?  Yes

Mohd Shoeb

  • Jul 13th, 2011
 

echo is the most primitive than print, and just output the content following the construct to the screen. print is also a construct (so parameter are optional when calling it), but it returns TRUE on successful output and FALSE, if it was unable to printout the string. However you can pass multiple parameters to echo(). echo is faster than print
the basic difference between echo() and print() are-
1. echo is just like a command and print() is a function.
2. print always returns the value in 1(true) or 0(false),

3. prints supports a single statement and echo supports a multiple statement
4. echo parsed reference variable on the other hand print doesn't

  Was this answer useful?  Yes

san

  • Jul 15th, 2011
 

Both are used in php as output Streams.

 

Code
  1. <?php

  2.  

  3. print("my india");

  4. ?>

  5. or

  6. <?php

  7. echo "my india"

  8. ?>

  Was this answer useful?  Yes

san

  • Jul 15th, 2011
 

Echo is faster than print....echo can execute more than 1 statements but print does not execute more than 1 statements.. It can execute only a single statement....

Code
  1. ?php>

  2. $sname="San","tosh";

  3. echo("San","tosh");

  4. print("San");

  5. ?>

  Was this answer useful?  Yes

gautam

  • Jul 27th, 2011
 

echo prints many values at a time

echo "first","second","third";

output:-

firstsecondthird

print() prints only one value i.e. its attribute

  Was this answer useful?  Yes

gautam

  • Jul 27th, 2011
 

echo prints multiple values

print () only one value

  Was this answer useful?  Yes

Heer Makwana

  • Jul 30th, 2011
 

Print will return TRUE/FALSE value while Echo doesn't return value and is little bit faster than Print.

  Was this answer useful?  Yes

Jim Tyson

  • Aug 1st, 2011
 

Sorry, this code confuses me.

Code


I can't work out what the value of $sname will be after line 2. You can't use a list like this in an assignment statement. Do you think the value of $sname should be "San" or "tosh"?

Why having initialised $sname do you use string literals in the following statements?

Finally again: print is a function - it returns success or failure with the display of the arguments as its side effect; echo is a construct with no return value and only the side effects - *and* echo can take multiple parameters.

Code
  1.  

  2.    1.

  3.       ?php>

  4.    2.

  5.       $sname="San","tosh";

  6.    3.

  7.       echo("San","tosh");

  8.    4.

  9.       print("San");

  10.    5.

  11.       ?>

  Was this answer useful?  Yes

pardeep khot

  • Aug 31st, 2011
 

echo is marginal faster than the print.
print behaves like a function but echo does not.
print take multiple argument but echo does not.

  Was this answer useful?  Yes

echo

•No return value
•Outputs one or more strings separated by commas

e.g. echo "String 1", "String 2"

print

•Returns 1, so it can be used in an expression
•Outputs only a single string

e.g. if ((print "foo") && (print "bar"))

  Was this answer useful?  Yes

santosh srinivas

  • Sep 9th, 2011
 

echo can print multiple lines at time,but in case of print it will execute single line......

  Was this answer useful?  Yes

abc

  • Sep 12th, 2011
 

php syntax same as that of perl & C..so echo used for printing in php and print in C

  Was this answer useful?  Yes

kumaran

  • Nov 14th, 2011
 

using print method can return a true/false value. This may be helpful during a script execution of some sort. Echo does not return a value, but has been considered as a faster executed command.

  Was this answer useful?  Yes

kanchan bhardwaj

  • Dec 9th, 2011
 

Echo- it is a command only and faster than print
Print-it is a functon & it will return true or false or some values.

  Was this answer useful?  Yes

sabareesh

  • Jan 2nd, 2012
 

Main difference between echo() and print() is that echo is simply a statement not a function which cannot returns the value but just print the statement where as print is a function which can print and return the value. We cannot pass argument to the echo because it is a statement where as we can pass argument to print because it is a function and it returns true or false values.

  Was this answer useful?  Yes

Premjith

  • Mar 21st, 2012
 

Both are language constructs. print behaves like a function and return value but actually it is not a function. echo never returns value
echo with out parenthesis takes multiple arguments print doesn't takes multiple arguments separated by commas

  Was this answer useful?  Yes

vetrivel .s

  • Apr 19th, 2012
 

Echo and print both are same.. mostly the developer using echo because it is execution speed faster than print...

  Was this answer useful?  Yes

ganta srinivasarao

  • Aug 17th, 2012
 

echo is a construct but print is a function. we can print two or more variables with help of echo but with help of print function only one..

  Was this answer useful?  Yes

Abhyuday kumar rai

  • Aug 31st, 2012
 

echo:- print:-
a)can accept multiple parameters. a)cant accept multiple parameters.
b)doesnt return any value. b)slower than echo.
c)faster than print. c)it returns a value either 0 or 1 depends on source.

  Was this answer useful?  Yes

Ramakrishna Reddy Gouni

  • Nov 29th, 2012
 

1. both are using to display the value.
2. echo is faster than print
3. echo displays multiple statements and variables but print only
4. print is function it returns a value.

  Was this answer useful?  Yes

Deepak Dholiyan

  • Dec 17th, 2013
 

Echo is the basic type used to print out a string. It just shows the content of the message written using it. It can have multiple parameters as well. print is a construct, it returns TRUE on successful output and FALSE there is no output.

  Was this answer useful?  Yes

Abinash Kumar

  • Jun 20th, 2017
 

echo does not returns a value and is faster than print. While print is a language construct that returns 1 which makes it slower in page than echo

  Was this answer useful?  Yes

Nakato

  • Aug 18th, 2017
 

echo() can be used as part of an expression, while print() cant

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions