adspace


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

What is the current stable version of php? What advance thing in php7?

1100


How can we extract string "pcds.co.in" from a string "https://info@pcds.co.in" using regular expression of php? More on reg can you explain

1082


How to create a web form?

1116


Explain me is it possible to destroy a cookie?

1035


What sized websites have you worked on in the past?

1092


Which variable declarations within a class is invalid in php?

1052


if you run the app program all vendor open items are cleared but is it possible to reverse the again again open items please tell me the answer

1997


How to calculate the difference between two dates using php?

1151


What is trait in php?

1072


What does $_files means?

1170


List some features of php that are deprecated in php7?

1026


What is the current stable version of php?

1130


how to detect a mobile device using php

1177


Tell me what kind of things have you done on the social side?

1071


Name and explain five of the PHP error constants?

1043