+ 1
What is the difference between echo and print in PHP??
šµš¼ššøš®šš»šøš
2 Answers
+ 5
echo
Outputs one or more strings separated by commas
No return value
e.g.Ā echo "String 1", "String 2"
print
Outputs only a single string
ReturnsĀ 1, so it can be used in an expression
e.g.Ā print "Hello"
or,Ā if ($expr && print "foo")
+ 2
They are both used to output data to the screen. TheĀ differencesĀ are small:echoĀ has no return value whileĀ printhas a return value of 1 so it can be used in expressions.Ā echoĀ can take multiple parameters (although such usage is rare) whileĀ printĀ can take one argument.Ā echoĀ is marginally faster thanĀ printĀ .