I cannot figure out a basic php interview question

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.