A basic php interview question cannot figure out echo '1'. print (2) + 3;
Let's talk about your answer and try it on the computer!
Reply to discussion (solution)
214. Let me give it a try. I cheated. I went to view the description of the print function.
511
Strange, right?
In fact, there is nothing strange
Print is actually not a real function (it is a language structure), so you do not need to use the parameter list of parentheses.
That is to say, print (2) + 3 is actually print 2 + 3
But he has a return value that is always 1.
511 this 5 is generated by print (2) + 3
5 11 this 1 is generated by echo '1'
51 1 This 1 is generated by print
Do you get 214 million? What is the php version?
214. Let me give it a try. I cheated. I went to view the description of the print function.
Do you get 214 million? What is the php version?
214. Let me give it a try. I cheated. I went to view the description of the print function.
';echo '1'.print(2);echo '
';echo print(2);echo '
';echo print(2)+3;echo '
';$tmp=print(2)+3;echo $tmp;echo '
';print(2)+3;echo '
';print '3';echo '
';?>
You started it too quickly. I just tried it.
Do you get 214 million? What is the php version?
214. Let me give it a try. I cheated. I went to view the description of the print function.
Didn't the landlord say that he would give the answer first and try again?
How can we say "I cheated?
214. Let me give it a try. I cheated. I went to view the description of the print function.
Although I have read the description of the function, I only read the type of the returned value. The habit of learning C language. I didn't even notice that the sentence is not a function. In addition, I didn't even notice that this is not a function after using echo for such a long time. I have learned VB before.
How can we say "I cheated?
I don't know what the returned value of print is. after reading the returned value, I will say my answer, so I am cheating.
I don't know. it hurts.
511
Strange, right?
In fact, there is nothing strange
Print is actually not a real function (it is a language structure), so you do not need to use the parameter list of parentheses.
That is to say, print (2) + 3 is actually print 2 + 3
But he has a return value that is always 1.
511 this 5 is generated by print (2) + 3
5 11 this 1 is generated by echo '1'
51 1 This 1 is generated by print
Why not it's 115?
Echo '1'. print (2) + 3;
The expression '1'. print (2) + 3 must be calculated before being passed to echo.
Print (2) + 3 print 5 and return 1
So 5 is at the beginning.
Echo actually prints '1'. 1 is 11
I understand. echo "1". (print "2") + 3;