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

I'm confused about static variables.

WBOY
Release: 2016-10-11 14:23:26
Original
994 people have browsed it

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>
Copy after login

If you want to use top-level scope variables in function scope, please add a sentence global $list;

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template