GeekInterview.com
Series: Subject: Topic:
Question: 77 of 98

What is the difference between echo and print?

If anyboyd knows, do tell me.
waiting for your prompt response.
Asked by: Interview Candidate | Asked on: Sep 25th, 2006
Showing Answers 1 - 43 of 43 Answers
Venu Gopal.M

Answered On : Sep 28th, 2006

Hi,

echo is a construct.echo takes multiple parameters

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

  
Login to rate this answer.
Ramesh

Answered On : Oct 4th, 2006

Hi,

echo :-

 - Is a command only.

 - Faster than Print.

print

 -

  
Login to rate this answer.
Ramesh

Answered On : 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.

  
Login to rate this answer.
Mahendra Choudhary

Answered On : 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.

  
Login to rate this answer.
rashmi

Answered On : Nov 2nd, 2006

echo is a statement and print is a function.

  
Login to rate this answer.
Bhupal

Answered On : 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.

  
Login to rate this answer.
anas

Answered On : 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.

  
Login to rate this answer.
Mohamed

Answered On : Dec 13th, 2006

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

  
Login to rate this answer.
ankita

Answered On : 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.

  
Login to rate this answer.
Raj

Answered On : Dec 21st, 2006

echo : just output the content

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

Yes  1 User has rated as useful.
  
Login to rate this answer.
Bhumita

Answered On : 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.

Yes  1 User has rated as useful.
  
Login to rate this answer.
Anand

Answered On : 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

  
Login to rate this answer.
bhoomika

Answered On : Feb 5th, 2007

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

  
Login to rate this answer.
hari krishnan

Answered On : 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

  
Login to rate this answer.
maurani

Answered On : May 5th, 2008

View all answers by maurani

echo() can take multiple expression bt print() cant

Yes  1 User has rated as useful.
  
Login to rate this answer.
sandep_dcte

Answered On : May 29th, 2008

View all answers by sandep_dcte

echo is not a function but print is a function echo is alias

echo can accept multiple argument

  
Login to rate this answer.
geek_sport

Answered On : May 31st, 2008

View all answers by geek_sport

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

  
Login to rate this answer.
sheeku

Answered On : Mar 6th, 2009

View all answers by sheeku

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.

  
Login to rate this answer.

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
?>

  
Login to rate this answer.
Joni Rajput

Answered On : May 12th, 2011

View all answers by Joni Rajput

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.

  
Login to rate this answer.
Jim Tyson

Answered On : May 21st, 2011

View all answers by Jim Tyson

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.

  
Login to rate this answer.
krbhupinder

Answered On : May 23rd, 2011

View all answers by krbhupinder

these 2 have same meaning.

  
Login to rate this answer.

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.

  
Login to rate this answer.
Mohd Shoeb

Answered On : Jul 13th, 2011

View all answers by Mohd Shoeb

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

  
Login to rate this answer.
san

Answered On : 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. ?>

  
Login to rate this answer.
san

Answered On : 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. ?>

  
Login to rate this answer.
gautam

Answered On : 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

  
Login to rate this answer.
gautam

Answered On : Jul 27th, 2011

echo prints multiple values

print () only one value

  
Login to rate this answer.
Heer Makwana

Answered On : Jul 30th, 2011

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

  
Login to rate this answer.
Jim Tyson

Answered On : 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.       ?>

  
Login to rate this answer.
pardeep khot

Answered On : 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.

  
Login to rate this answer.
sudhasri7777

Answered On : Sep 5th, 2011

View all answers by sudhasri7777

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"))

  
Login to rate this answer.
santosh srinivas

Answered On : Sep 9th, 2011

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

  
Login to rate this answer.
abc

Answered On : Sep 12th, 2011

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

  
Login to rate this answer.
kumaran

Answered On : 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.

  
Login to rate this answer.
kanchan bhardwaj

Answered On : 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.

  
Login to rate this answer.
sabareesh

Answered On : 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.

  
Login to rate this answer.
ganeshpapde

Answered On : Feb 21st, 2012

View all answers by ganeshpapde

echo or print r d functions ....echo is mostly we r using in php

  
Login to rate this answer.
Premjith

Answered On : 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

  
Login to rate this answer.
vetrivel .s

Answered On : Apr 19th, 2012

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

  
Login to rate this answer.
ganta srinivasarao

Answered On : 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..

  
Login to rate this answer.
Abhyuday kumar rai

Answered On : 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.

  
Login to rate this answer.
Ramakrishna Reddy Gouni

Answered On : 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.

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.