+ 1

What is the difference between echo and print in PHP??

šŸµšŸŒ¼šŸ’šŸŒøšŸ’®šŸ’šŸŒ»šŸŒøšŸ’

23rd Apr 2019, 12:34 PM
Nithya Yamasinghe
Nithya Yamasinghe - avatar
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")
23rd Apr 2019, 12:48 PM
Bilal Ahmed
Bilal Ahmed - avatar
+ 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Ā .
23rd Apr 2019, 12:36 PM
Alessio Benvenuti
Alessio Benvenuti - avatar