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

What is the difference between print, return and echo statement in php ?

13th May 2017, 7:30 AM
Siddharth Saraf
12 Respuestas
+ 19
Good Question :) return is a language construct used to exit a function and give a value to the caller of the function. echo and print are both language constructs that output strings. The main difference is that echo can take multiple arguments separated by commas, but print accepts only a single argument.
13th May 2017, 7:35 AM
Dev
Dev - avatar
13th May 2017, 8:02 AM
Dev
Dev - avatar
+ 10
I seriously didn't study PHP, but good explanation Dayve!
13th May 2017, 7:37 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 8
BTW Dave how do you not learn any language but you're close to Platinum?
13th May 2017, 7:57 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 8
@Dayve Oh nice! Thanks for the info!
13th May 2017, 8:03 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
.TV kx1c cnn ex k qbw.4f x4 quite c 2c k 4cccwx
24th Jul 2017, 10:50 PM
richard.kahute
richard.kahute - avatar
+ 2
Just note that print will return 1 always, but echo will not. Also, echo is a little bit faster.
22nd Jul 2017, 4:19 AM
$machitgarha
$machitgarha - avatar
+ 2
. ob
24th Jul 2017, 10:50 PM
richard.kahute
richard.kahute - avatar
+ 1
echo and print are both language construct
13th May 2017, 8:00 PM
yakubu
+ 1
2k wlwicc1 4eq1 ww isbj.quv2c , lbe6tl 9
24th Jul 2017, 10:50 PM
richard.kahute
richard.kahute - avatar
0
That was a typo. I can't remember what the question was, but I've been fiddling around with Debian Linux and DNS stuff. I'm not going to master a language soon, may as well learn networks. I'd trade the ability to to run fast(which I can btw) for C+ downloaded to you brain.
30th Jan 2018, 8:55 AM
richard.kahute
richard.kahute - avatar
0
print has a return value of one (1), while echo has zero (0) value and thus can be used in expressions. Print is more common but echo more versatile. I guess echo is for math teachers who wrote their own tests in Python. Who knows ?
30th Jan 2018, 9:02 AM
richard.kahute
richard.kahute - avatar