php静态变量的销毁


什么都不说,先上代码:

 1     public function _childrenids($data,$cate_id,$clear=false)
 2     {
 3         static $arr = array();
 4         if ($clear)
 5         {
 6             $arr = array();
 7         }
 8         foreach ($data as $k => $v)
 9         {
10             if($v['pid'] == $cate_id)
11             {
12                 $arr[] = $v['id'];
13                 $this -> _childrenids($data,$v['id']);
14             }
15         }
16         return $arr;
17     }

在代码里面,我们知道了 $arr是静态变量。

但是,一般的注销是不能注销静态变量的:

来源:http://php.net/manual/zh/function.unset.php

所以,我们要注销一个静态变量,只能通过重新定义的方式进行清空!!!


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM