已经有数据 id fid 23 0 27 23 28 23 34 38 33 0 //getID 是从数据库取出来的,目前 23 和 33 foreach ($getID as $k => $v) { $allAgentID = getAllID($v); print_r($allAgentID); } function getAllID($uid){ global $empire,$dbtbpre,$userid; $userid[] =$uid ; $s= "select userid from {$dbtbpre}enewsmember where fid='".$uid."' and checked=1 order by userid asc"; $sql=$empire->query($s); while($u=$empire->fetch($sql)) { getAllID($u[userid]); } return $userid; } //输出结果 Array ( [0] => 23 [1] => 27 [2] => 28 [3] => 34 ) Array ( [0] => 23 [1] => 27 [2] => 28 [3] => 34 [4] => 33 ) 为什么当$v=33的时候没有清楚之前的数组,还把之前的数组合并在一起 请问有什么办法能得到以下数组吗? 当$v=23时 Array ( [0] => 23 [1] => 27 [2] => 28 [3] => 34 ) 当$v=33时 Array ( [4] => 33 )
Because you are using a global variable, it will not be destroyed during the running of the entire program. Generally, it will appear when you call this method in a piece of code. If it is only called once in the page, there is no problem in writing it this way.
You can change your mind and change the recursive call below. Try not to use global ones. Here, you can directly use an array variable to handle it.
Can you please help me? I’ve been stuck at work for a long time