Jump to content

output


mrneilrobinson

Recommended Posts

I think the OP means why not how.

 

First, it is important to note that print is not a function so may cause confusion when called like one! The parentheses in the example code above are meaningless and only serve to give the false impression that the line of code will behave like normal function calls.

 

When PHP evaluates the following line:

 

echo print('3').'2'.print('4');

It might as well be:

 

echo print '3' . '2' . print '4';

Both are identical. If we were to use parentheses to represent what is evaluated together it would look like:

 

echo (print '3' . '2' . (print '4'));

 

Working through this as PHP does:

1. Concatenate "3" with "2" to get "32"

2. Print "4"

3. Concatenate "32" with the return value from the second print (integer 1) to get "321"

4. Print "321"

5. Echo the return value from the first print (integer 1) so echo "1"

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.