I have a user table with hierachical users. So users can have a parent user. I am trying to return an array of all child user ids of a certain user. My function returns "null". What's wrong?
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;
}
}