A basic PHP interview question, don't think

Source: Internet
Author: User
echo ' 1 '. Print (2) +3;

Say your answer, then go to the computer to try!


Reply to discussion (solution)

214. I'll try. I cheated, I went to read the function description of print.

511

That's weird, isn't it?
Actually, it's nothing strange.
Print is not actually a real function (it is a language structure), so you do not need to use the parentheses argument list.
Which means 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 produced by the Echo ' 1 '
51 1 This 1 is generated by print.

Are you really 214? What is the PHP version?

214. I'll try. I cheated, I went to read the function description of print.

Are you really 214? What is the PHP version?


214. I'll try. I cheated, I went to read the function description of print.

 
  '; Echo ' 1 '. Print (2); Echo '
'; echo print (2); Echo '
'; echo print (2) +3;echo '
'; $tmp =print (2) +3;echo $tmp; Echo '
';p rint (2) +3;echo '
';p rint ' 3 '; Echo '
';? >

You've done so fast, I've just tried to feel something.

Are you really 214? What is the PHP version?


214. I'll try. I cheated, I went to read the function description of print.
Landlord is not to say first answer to try again?

What do you mean, "I cheated"?

214. I'll try. I cheated, I went to read the function description of print.
Although I looked at the description of the function, I only looked at the type of the return value. Learn the habit of C-language cultivation. That's not a function I didn't even notice. In addition Echo took so long time unexpectedly also didn't notice this is not function, previously learned VB reason bar.

What do you mean, "I cheated"?
I don't know what the return value of print is, and then look at the return value and say my answer, so I cheated.

I don't know, the egg hurts.

511

That's weird, isn't it?
Actually, it's nothing strange.
Print is not actually a real function (it is a language structure), so you do not need to use the parentheses argument list.
Which means 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 produced by the Echo ' 1 '
51 1 This 1 is generated by print.
Why not 115?

echo ' 1 '. Print (2) +3;
In ' 1 '. Print (2) +3 This expression must be evaluated before it is passed to the Echo
While print (2) +3 prints 5 and returns 1
So the 5 came to the front.
echo actually prints ' 1 '. 1 That's 11

I understand, the cheating is 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.