开发者

The echo and print statements in php [duplicate]

This question already has answers here: Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜