Jump to content
Larry Ullman's Book Forums

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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...