学了一个递归

来源:互联网 发布:淘宝开店策划方案 编辑:程序博客网 时间:2024/04/24 23:12
public function getchildid($id,$parentidArr){
$user = M('User');
$userRs = $user->find($id);
$parentid = $userRs['parentid'];
if($parentid>0){
$parentidArr[] = $parentid;
return $this->getchildid($parentid,$parentidArr);
}
return $parentidArr;
}


$parr = $this->getchildid(4,array('4'));
var_dump($parr);
exit();


/**激活后保存激活ID**/
// $update_act_num['activeid']=$active_total_count;
// $update_act_num['bianhao'] = date('YmdHis')."00".$active_total_count;
// $update_act_num_Rs = $this->dao->where($map)->save($update_act_num);




if($isshenheCount==63){
//var_dump(expression);
//设置出局
$outmap['level']=array('eq',1);
$outrs = $this->dao->where($outmap)->order('activeid asc')->field('id')->limit('0,1')->find();
$outid = $outrs['id'];
$outdata['out']=1;
$saveout = $this->dao->where('id = '.$outid)->save($outdata);


//拆分组
$split_parentid_list = $this->dao->where('parentid='.$outid)->field('id')->order('activeid asc')->select();
//分组1
$ownerid_0 = $split_parentid_list[0]['id'];
$owner_0 = $this->dao->field('id,arrchildid')->find($ownerid_0);
$group_childstr_0 = explode(',', $owner_0['arrchildid']);
foreach ($group_childstr_0 as $key => $g_value0) {
$group_childdata_0['groupnum'] = $owner_0['id'];
$group_update_rs_0 = $this->dao->where('id='.$g_value0)->save($group_childdata_0);
}


//分组1
$ownerid_1 = $split_parentid_list[1]['id'];
$owner_1 = $this->dao->field('id,arrchildid')->find($ownerid_1);
$group_childstr_1 = explode(',', $owner_1['arrchildid']);
foreach ($group_childstr_1 as $key => $g_value1) {
$group_childdata_1['groupnum'] = $owner_1['id'];
$group_update_rs_1 = $this->dao->where('id='.$g_value1)->save($group_childdata_1);
}
}
0 0
原创粉丝点击