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

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

原文地址:https://www.cnblogs.com/laijinquan/p/10197880.html