Why are the output results ccc? {Code...} but cannot change the array? {Code...} and this will add elements to the array? {Code...} hopes to explain the principle: :) why are the output results ccc?
But this cannot change the array?
And this will add elements to the array?
static $arr = array();$arr[] = 'sdsds';$arr[] = 'xxx';var_dump($arr);static $arr = array('ww', 'vv');var_dump($arr);I hope I can talk about the principle :)
Reply content:Why are the output results ccc?
But this cannot change the array?
And this will add elements to the array?
static $arr = array();$arr[] = 'sdsds';$arr[] = 'xxx';var_dump($arr);static $arr = array('ww', 'vv');var_dump($arr);I hope I can talk about the principle :)
Static is generally used in functions or classes.
I think the php engine will refer the static declaration to the top of the domain when scanning static.
It becomes
The next step evolved
The third has evolved
Static variables have been initialized before execution. No matter how many times it is initialized, it is only useful for the last time. You can assign values without static values.
All of you
static $xxx = xxx;
Only the last sentence is useful.
The following code can help you clarify your ideas:
The result is:
array (size=2) 0 => string 'gga' (length=3) 1 => string 'gaga' (length=4)
When the second array is defined for the second time, It is null and should be ignored.
Change the second definition of the first one to ''to see the result.
Learning...