Write the output result of the php segment:
<?php $count=5;function get_count(){ static $count=0; return $count++;}echo $count;++$count;echo get_count();echo get_count();?>
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/--> <? Php $ a = 3; echo ++ $ a; // pre-type. The result is 4 after auto-increment. In this case, $ a is 4 $ B = 3; echo $ B ++; // post-type: Output 3 first, and then auto-increment to 4. At this time, $ B is 4?>
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.