输出结果是
如果去掉静态static的话
$arr=array();$arr[]=1;$arr=array();$arr[]=2;$arr=array();$arr[]='haha'; var_dump($arr);
输出结果是:
~,为什么静态变量重复声明了多次,也相当于只声明了一次呢???~
Reply content:
输出结果是
如果去掉静态static的话
$arr=array();$arr[]=1;$arr=array();$arr[]=2;$arr=array();$arr[]='haha'; var_dump($arr);
输出结果是:
~,为什么静态变量重复声明了多次,也相当于只声明了一次呢???~
Static variable fixed in memory address, non-static variable memory address is not fixed, can be changed
In general, static variables are statically assigned, and their life cycle is the same as the life cycle of the program, which only ends the life cycle of a program when it exits, which, contrary to local variables, In some languages, global variables are also statically assigned. For example, global variables in PHP and JavaScript.
Can read a book Http://www.php-internals.com/book/?p=chapt03/03-04-static-var
will help you
Declaration and assignment are not the same, such as
!--? Phpstatic $ Arr=array (); $arr []=1;static $arr =array (); $arr []=2;static $arr =array (); $arr = Array (); $arr []= ' haha '; var_dump ($arr);
run result is:
" Array (1) {[0]= > String (4) "Haha"}