PHP auto-increment and auto-increment

Source: Internet
Author: User
Tags variable scope
PHP auto-incrementing write the output result of the php segment:

 

The answer is: 501.

It involves two knowledge points:

1. php variable scope;

2. Auto-increment/auto-increment variables;

The interviewer understands the scope of "php variables" well, but he is not sure about "auto-increment/auto-increment variables. The following is a review for your reference:

Auto-increment/subtraction is divided into front and back, which involves a sequence:

Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/-->
 

Problem: if $ I = 2, evaluate the value of the expression ($ I ++) * ($ I ++) and the value of $ I

Answer: ($ I ++) * ($ I ++) the result is 24, and $ I is 5.

Analysis: first look at the calculation order. if there are parentheses, first calculate the values in the brackets. First, take the value of $ I 2 as ($ I ++, then $ I Auto-increment is 3; [at this time ($ I ++) left = 2, $ I = 3]

In the brackets, set the value of $ I 3 to ($ I ++), and then add $ I to 4. [at this time ($ I ++) medium = 3, $ I = 4]

Right after the parentheses, take the value 4 of $ I at this time as the value of ($ I ++), and then add $ I as 5.

Perform the multiplication operation, that is, 2*3*4 = 24 $ I = 5.

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.