Home >Backend Development >PHP Tutorial >I'm confused about static variables.

I'm confused about static variables.

WBOY
WBOYOriginal
2016-10-11 14:23:261004browse

It’s okay to write an Infinitus category

I'm confused about static variables.
Found that the last static variable was empty,

Modification, put the static variables into the function, and the array is correctly classified

I'm confused about static variables.

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

Reply content:

It’s okay to write an Infinitus category

I'm confused about static variables.
Found that the last static variable was empty,

Modification, put the static variables into the function, and the array is correctly classified

I'm confused about static variables.

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;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn