What is the difference between echo and print in PHP?? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

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

🏵🌼💐🌸💮💐🌻🌸💐

23rd Apr 2019, 12:34 PM
Nithya Yamasinghe
Nithya Yamasinghe - avatar
2 Respuestas
+ 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