Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 三元树的深度-传销级别_Php_Wordpress_Tree_Mlm_Ternary Tree - Fatal编程技术网

Php 三元树的深度-传销级别

Php 三元树的深度-传销级别,php,wordpress,tree,mlm,ternary-tree,Php,Wordpress,Tree,Mlm,Ternary Tree,我正在用php开发一个MLM,其中每个节点只能有3个子节点。传销有N个级别。 任何父节点的级别将等于其子节点的最低级别+1。深度n处的子级的级别为1 function calculate_level($starId=0) { if($starId == null) return 1; $result = getAllChildren($starId); if($result && count((array)$result) == 3){ return 1 + mi

我正在用php开发一个MLM,其中每个节点只能有3个子节点。传销有N个级别。 任何父节点的级别将等于其子节点的最低级别+1。深度n处的子级的级别为1

function calculate_level($starId=0) {

if($starId == null) return 1;

$result = getAllChildren($starId);

if($result && count((array)$result) == 3){

    return 1 + min(calculate_level($result[0]->user_ref_id),calculate_level($result[1]->user_ref_id),calculate_level($result[2]->user_ref_id));

}else{ return 1;}
}

}

数据库布局图像

预期结果

我怎样才能做到这一点

谢谢

function level_calculator($starId = 0) {

$result = getAllParents($starId);

//now we have all parents of current star now we need to find the level for each.

foreach($result as $res){

    if($res->user_status == 3 ){

        //we only update level if status == 3

        $level = calculate_level($res->user_ref_id);

        echo  $level  .':' . $res->user_ref_id .',';


    }
}