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.