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
https://forums.phpfreaks.com/topic/182015-output/#findComment-960120
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.