PHP recursion problem, please help
给你一个大大的么么
给你一个大大的么么 2017-11-17 11:37:06
0
3
987
已经有数据 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 )


给你一个大大的么么
给你一个大大的么么

reply all (2)
易风课堂

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.

  • reply Thank you, I added a & in getAllID($uid) getAllID(&$uid) will do the trick.
    给你一个大大的么么 author 2017-11-20 10:05:45
给你一个大大的么么

Can you please help me? I’ve been stuck at work for a long time

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!