Home >Backend Development >PHP Tutorial >I'm confused about static variables.
It’s okay to write an Infinitus category
Found that the last static variable was empty,
Modification, put the static variables into the function, and the array is correctly classified
I always thought I had figured out the static variables. As soon as this problem came up, I knew that I didn’t fully understand the static variables
It’s okay to write an Infinitus category
Found that the last static variable was empty,
Modification, put the static variables into the function, and the array is correctly classified
I always thought I had figured out the static variables. As soon as this problem came up, I knew that I didn’t fully understand the static variables
This is a scope issue.
$list in
noLimit
is not the same as $list
in top-level scope
<code> $list = []; function shit() { $list[] = "shit"; var_dump($list); } shit(); // 输出 array(1) { [0]=> string(4) "shit" } var_dump($list); // 输出 array(0) { }</code>
If you want to use top-level scope variables in function scope, please add a sentence global $list;