The echo and print statements in php [duplicate]
Possible Duplicate:
What is basic difference echo Vs print
The echo and print statements are nearly identical, but they have some differences. For example, the print statement returns a value of 1 if it is successful or a value of 0 if it is not successful, while the echo statement does not return开发者_Python百科 a value.
why print statement returns a value of 1 if it is successful. but echo doesn't. thank you
I've actually taken advantage of the return value of the print "function" in an ajax call:
return print json_encode($my_data);
It doesn't do anything at all with the return value, but it terminates the execution of the current script, which is a slightly prettier way of writing
echo json_encode($my_data);
die();
But as to why one returns something and the other doesn't.... probably isn't a terrible good reason for it. I reckon echo is ever so slightly (negligibly) faster because of it, whereas print has weird uses such as the aforementioned one.
As to what these other guys are saying about print()
not being a language construct, but a function, I say to you, read the manual. It's a language construct too.
精彩评论