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 |
<?php include ("db.php"); $result = mysql_query("SELECT ques_id FROM questionbank order by ques_id limit 5 "); while($obj=mysql_fetch_array($result)) { $ad1[$obj['ques_id']]++;//Used an array and inserted the database query results into it. } $rand_keys=array_rand($ad1,1); //Did a random array function echo "First random id = ".$ad1[$rand_keys[0]]; echo "<br>Second random id = ".$ad1[$rand_keys[1]]; ?> <!--Its not working. Have any solution for this. -->
What’s the special meaning of __sleep and __wakeup?
What is static variable in php?
I created a cookie with the value like '1A2A',now i want to update this value regularly (about 20 times in a minute) with the value '1A2A3A' , 3A is the new value,new value will vary on the request it may be 3A or 4A or 100A ,some times the cookie is updating with new value but not every time.Can any body suggest the solution
What backslash character will match whitespace?
What are the correct and the most two common way to start and finish a PHP block of code?
What is indexing how many types?
3 Answers DLF, Infosys, Net Solution, Vcare,
What is the default session time in PHP and how can I change it?
What is a string in php?
m new to xampp i want to configure file server in xampp... is it possible ??? if so help me....
How send email using php?
Which is the best institute in Chennai to learn PHP? Please help.