What is the Diff. Between echo() and Print() in PHP?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the difference between array_merge() and array_combine()?

535


What is the use of 'print' in php?

548


What is the use of "enctype" attribute in a html form?

527


Is php easy language to learn?

575


How to get the number of characters in a string?

567






What are php applications?

512


Does php need a closing tag?

548


Difference between get and post method.

545


How to run a php script?

572


What is php glob?

571


What is the difference between myisam and innodb?

508


Can we override magic methods in php?

534


What is advanced php programming?

541


Which is not a file-related function in php?

611


What is the functionality of the functions strstr() and stristr()?

525