Jump to content
Larry Ullman's Book Forums

Print Returns An Integer Value


Recommended Posts

Page 18 of the book refers to the print function in the PHP manual - http://www.php.net/print. It says:

 

...the first value, int, says that print returns an integer value (specifically, print returns 1, always...

 

I know how print "something" outputs a string, but I have no understanding as to how print always returns 1. Could someone please explain what is meant by the statement I quoted?

 

Thanks!

Link to comment
Share on other sites

In this particular case, the fact that print returns 1 is meaningless. Or not meaningless, but not useful. What print does is output a string, but the function returns the integer 1. Normally the returned value is not used, but you could do this:

 

if (print('Hello, world')) { ...

 

That's how you might otherwise use a function that returns a "true" value. In this case, there's no need to ever do that because print always returns 1. Still, I use print() as an easy first example, because it's easy to understand what the function does and its definition.

Link to comment
Share on other sites

 Share

×
×
  • Create New...