数组中查找所有的上级 并组成新的数组(根据条件可以再修改)

来源:互联网 发布:数据分析培训课程excel 编辑:程序博客网 时间:2024/05/16 17:24
<?php 
$menuarr=Array(    [1] => Array        (            [title] => 开发部            [type] => 0        )    [2] => Array        (            [title] => 销售部            [type] => 0            [230] => Array                (                    [title] => jykk                    [type] => 1                )        )    [3] => Array        (            [title] => 生产部            [type] => 0            [5] => Array                (                    [title] => 生产部2                    [type] => 0                    [242] => Array                        (                            [title] => rrrrrr                            [type] => 0                            [244] => Array                                (                                    [title] => 4444444                                    [type] => 1                                )                        )                )            [6] => Array                (                    [title] => 生产部3                    [type] => 0                    [235] => Array                        (                            [title] => 22                            [type] => 0                        )                    [236] => Array                        (                            [title] => 22                            [type] => 0                        )                    [237] => Array                        (                            [title] => 22                            [type] => 0                        )                    [238] => Array                        (                            [title] => 22                            [type] => 0                        )                    [239] => Array                        (                            [title] => 22                            [type] => 0                        )                    [240] => Array                        (                            [title] => 22                            [type] => 0                        )                )            [195] => Array                (                    [title] => 开发部0                    [type] => 0                    [229] => Array                        (                            [title] => 1                            [type] => 1                        )                )            [232] => Array                (                    [title] => vfff                    [type] => 0                    [233] => Array                        (                            [title] => ettrt                            [type] => 1                        )                )        )    [226] => Array        (            [title] => 人事部            [type] => 0            [227] => Array                (                    [title] => kugoo                    [type] => 1                )            [245] => Array                (                    [title] => 55Q                    [type] => 0                    [246] => Array                        (                            [title] => 55554                            [type] => 1                        )                )        ))

//在上面数组中查找 值为 rrrrrr 的那维数组:

 

return_team_arr("rrrrrr" ,$menuarr) ;

 

function return_team_arr($research_value,$research_array){
     static $org_array;
     static  $found_array;
     if(!isset($org_array))
         $org_array  =  $research_array;

  foreach($research_array  as  $key => $value){  
     if(strstr(trim($value['title']),$research_value)){
      $found_array =  array( $key => $value); #echo trim($value['title']); #echo "<pre>";  print_r($found_array);  echo "</pre>";
                                                           
      if(isset($research_array['title']) && $research_array['title'] != "" ){ #终止查找的条件
       $research_value = $research_array['title'];  #echo "<pre>";  print_r($org_array);  echo "</pre>";
       return_team_arr($research_value,$org_array);
      }else
       break;
     }else{
      return_team_arr($research_value,$value);
     }
  }
  
  return  $found_array;
}

 

 

?>

 

 

 

原创粉丝点击