• PHP递归获取相关节点


    		$temp = [
    	        [
    	            'id'=>12,
                    'sid'=>1,
                    'pid'=>999,
                    'gid'=>999,
                ],
                [
                    'id'=>13,
                    'sid'=>2,
                    'pid'=>999,
                    'gid'=>999,
                ],
            ];
            $found_key = array_search(40489, array_column($userdb, 'uid'));
    		
    		
    		$meng = new Changeofscene;
            $array = $meng->queryChange();
    		echo "<pre>";
    		print_r($array);exit();
    		
    		
    		, [
                'id' => 64,
                'se' => 5,
            ], [
                'id' => 68,
                'se' => 5,
            ]
    		
    		
    		
    		
    		$data = [[
                'id' => 12,
                'pid'=> 9,
                'se' => 1,
            ], [
                'id' => 13,
                'pid'=> 9,
                'se' => 1,
            ]];
    
            $meng = new Changeofscene;
            $array = $meng->queryChange();
    		
    		public function findOne($data,$all){
            $newArr = [];
            foreach ($data as $k=>$v){
                $newArr[] = $v['id'];
                $newArr[] = $v['pid'];
                $found_keys = array_search($v['pid'], array_column($array, 'value'));
                if($found_keys){
                    $newArr[] = $array[$v['pid']]['sequence'];
                }
            }
            echo "<pre>";
            print_r($newArr);exit();
        }
    	
    	
    	
    	
    	
    	$data = [ [
                'id' => 167,//实时购买->赎回->理财产品->理财保险->个人业务场景->场景
                'pid'=> 153,
                'se' => 5,
            ], [
                'id' => 12,
                'pid'=> 9,
                'se' => 1,
            ], [
                'id' => 147,//签约
                'pid'=> 96,
                'se' => 5,
            ]];
    	//获取上级所有节点
        private function parent_tree_data($list, $child, &$trees = [])
        {
            $tree = array();
            foreach ($list as $k => $row) {
                if($row['value'] == $child) {
                    $trees[] = $row['sequence'];
                    $this->parent_tree_data($list, $row['sequence'],$trees);
                    //$row['parent'] = $this->parent_tree_data($list, $row['sequence'],$trees);
                    //$tree[] = $row;
                }
            }
            return $trees;
        }
        //获取下级所有节点
        private function children_tree_data($list, $child, &$trees = [])
        {
            $tree = array();
            foreach ($list as $k => $row) {
                if ($row['sequence'] == $child) {
                    $trees[] = $row['value'];
                    $this->children_tree_data($list, $row['value'], $trees);
                    //$row['children'] = $this->children_tree_data($list, $row['value'], $trees);
                    //$tree[] = $row;
                }
            }
    
            return $trees;
        }
        //获取相关所有节点
        public function findOne($data, $array)
        {
            $newArr = [];
            foreach ($data as $k => $v) {
                $newArr[] = $v['id'];
                $newArr[] = $v['pid'];
                $newArr = array_merge($newArr,$this->parent_tree_data($array, $v['pid']),$this->children_tree_data($array, $v['id']));
                //$newArr[] = $this->parent_tree_data($array, $v['pid']);
                //$newArr[] = $this->children_tree_data($array, $v['id']);
            }
            $newArr = array_unique($newArr);
            sort($newArr);
            /*echo "<pre>";
            print_r($newArr);exit();*/
            return $newArr;
        }
    		
    

      

  • 相关阅读:
    ACM-ICPC 2018 徐州赛区网络预赛 G题
    ACM-ICPC 2018 沈阳赛区网络预赛 K题
    ACM-ICPC 2018 沈阳赛区网络预赛 K题
    数据结构实验之栈与队列七:出栈序列判定
    数据结构实验之栈与队列七:出栈序列判定
    Python isspace()方法
    Python isnumeric()方法
    Python islower()方法
    Python isdigit()方法
    Python isdecimal()方法
  • 原文地址:https://www.cnblogs.com/meetuj/p/11770732.html
Copyright © 2020-2023  润新知