I saw an interview question today, which involves a very elementary question, as shown below:
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:
<? Php
$ A = 3;
Echo ++ $ a; // The frontend 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.
?>
The principle of auto-Subtraction is the same as that of auto-increment.