1
我有一个用户表和分层用户。所以用户可以有一个父用户。我正在尝试返回某个用户的所有子用户ID的数组。 我的函数返回“null”。怎么了?concat tree hierarchie在递归PHP函数中
public function userDownline($userid, $result = array()) {
$dbconn = $this->DBase();
$children = $dbconn->GetAll('SELECT id FROM users WHERE parent=' . (int)$userid);
if(count($children) > 0) {
foreach($children As $k=>$v) {
if(!in_array($v['id'], $result)) $result[] = $v['id'];
$this->userDownline($v['id'], $result);
}
} else {
return $result;
}
}
谢谢 - 我加了一个“回”到上述线路 - 现在我得到了第一个孩子(1条记录,而不是许多)。 – Gerfried
mikehillyer网站真棒 - 谢谢!为此+1。 – Gerfried
我再次看了一遍,并用代码更新了我的答案。 – vuliad