What is the Diff. Between echo() and Print() in PHP?
Answers were Sorted based on User's Feedback
Answer / satish
echo is language construct. print is function. echo is
faster. langauge constructs are faster than functions,
always. echo may tek mutiple arguments as well. echo
doesn't give return value.
Is This Answer Correct ? | 6 Yes | 2 No |
Answer / arvind pippal
echo is the multiple funtion,print does not multiple
parameters. It is also generally argued that echo is
faster, but usually the speed advantage is negligible, and
might not be there for future versions of PHP.
advantages as formatted output, but it’s the slowest way to
print out data out of echo, print.
Is This Answer Correct ? | 13 Yes | 10 No |
Answer / nidz
echo and print both are not functions but a
construct...print can be used as function ...Can anybody
tell me what is construct ?
Is This Answer Correct ? | 8 Yes | 5 No |
Answer / pushp
Echo has slight performance advantage because it does not
return value.
Is This Answer Correct ? | 7 Yes | 4 No |
Answer / rajiv_cogzidel
echo() doesn't return anything. But print() return true or
false.
You can give output for print() using echo(). You can notice
here print having true. So it give output 1.
Because print is a function. So it return true or false. But
echo is an statement. So it will not.
Ex:-
echo(print(d));
Output:-
d1
But you can't do this using print like this
Ex:-
print(echo(d));
Output:-
Parse error: syntax error, unexpected T_ECHO in
E:\xampp\htdocs\rajiv\valid.php on line 119
And other thing is echo() allow multiple strings using
separated by comma(,).
Here are examples
using echo()
ex:-
echo "Rajiv","\n","K.C","\n","\nHello World!","\nAgain Hello
World!";
output:-
Rajiv K.C Hello World! Again Hello World!
using print()
ex:-
print "Rajiv","\n","K.C","\n","\nHello World!","\nAgain
Hello World!";
output:-
Parse error: syntax error, unexpected ',' in
E:\xampp\htdocs\rajiv\valid.php on line 130
Some one says we cannot use double quotes in single quote.
But it's not true. It will work. Here are examples
print 'print"hai"hoo';
echo 'echo"hai"hoo';
These two give output.
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / vinay sachan
There are many differences in print() and echo() :-
1-echo is unformatted whereas print is formatted.
2-echo() can take multiple expressions, Print cannot take multiple expressions.
ex.-
<?php
$name="Vinay";
echo "Name is $name";
//Value is Vinay
print 'Name is $name';
//Value is $name
?>
3-Print return true or false based on success or failure whereas echo just does what its told without letting you know whether or not it worked properly.
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / surendra.kandimalla
Echo:echo as a function we can pass only one argument.But echo as command we can pass any number of arguments.echo will not return anything.
echo("echo as function<br>");
echo"arg1","arg2","arg3","<br>";
Print:we can pass only one argument for print as function or command.print returns boolean value.
print("print function<br>");
$b=print"print command<br>";
echo $b,"<br>";
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / kroonal
echo() have multiple arguments whereas print() have one
arguments. echo() have not any return value whereas print()
return 0 or 1 as per success
Is This Answer Correct ? | 0 Yes | 0 No |
What is the importance of parser in php?
What are html entities?
Write a program in php to find the occurrence of a word in a string?
how we can retrive data in pdf along php mysql?
What is mem_cache ? How do you put a database query into that ?
What is the interface in php?
Which is better session or cookie?
How to write the form tag correctly for uploading files?
How can I use the COM components in php?
1 Answers Covansys, Rushmore Consultancy,
What is difference between required and require_once in php?
What changes I have to do in php.ini file for file uploading?
Which software is used to run php programs?