mrneilrobinson Posted November 18, 2009 Share Posted November 18, 2009 echo print('3').'2'.print('4'); how do i get this code to output 43211? thankyou in advance Quote Link to comment https://forums.phpfreaks.com/topic/182015-output/ Share on other sites More sharing options...
abazoskib Posted November 18, 2009 Share Posted November 18, 2009 echo 43211; Quote Link to comment https://forums.phpfreaks.com/topic/182015-output/#findComment-960082 Share on other sites More sharing options...
sasa Posted November 18, 2009 Share Posted November 18, 2009 echo print('3').'2'.print('4'); how do i get this code to output 43211? thankyou in advance just run it Quote Link to comment https://forums.phpfreaks.com/topic/182015-output/#findComment-960118 Share on other sites More sharing options...
salathe Posted November 18, 2009 Share Posted November 18, 2009 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" Quote Link to comment https://forums.phpfreaks.com/topic/182015-output/#findComment-960120 Share on other sites More sharing options...
premiso Posted November 18, 2009 Share Posted November 18, 2009 Smells like homework to me. Read your book Quote Link to comment https://forums.phpfreaks.com/topic/182015-output/#findComment-960130 Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2009 Share Posted November 18, 2009 Based on the string of topics being started, several so hastily made they were not even in the correct forum section, it is probably an exam of some kind. Quote Link to comment https://forums.phpfreaks.com/topic/182015-output/#findComment-960134 Share on other sites More sharing options...
mrneilrobinson Posted November 18, 2009 Author Share Posted November 18, 2009 many thanks for your help, homework indeed, however in the brief i was asked to use forums. Quote Link to comment https://forums.phpfreaks.com/topic/182015-output/#findComment-960178 Share on other sites More sharing options...
salathe Posted November 18, 2009 Share Posted November 18, 2009 homework indeed I feel so used. However, you'll have fun explaining things to whoever marks your homework. Don't forget to tell your teacher/tutor/professor how helpful and nice PHPFreaks people were. Quote Link to comment https://forums.phpfreaks.com/topic/182015-output/#findComment-960226 Share on other sites More sharing options...
tonymcnulty Posted November 19, 2009 Share Posted November 19, 2009 It was an exam, for a job at my company. I found this by searching the answer text! Just registered to say that's a great explanation salathe. Actually the best answer we've had so far Quote Link to comment https://forums.phpfreaks.com/topic/182015-output/#findComment-961180 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.