【调度系统】广东民航医疗快线调度系统源代码
wzp
2025-05-06 18c7a44d2e9db3f4a5322389c3ee94468cce4de1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php require '/inc/odbc.php';
    
 
    $ArrDepartmentData=array();
    $sqls = "select id,vID,vtext,vType,vOrder,vtitle from dictionary as a where vtitle='OA_Department' and vType>=0 order by vOrder desc" ;
        $data = sqlsrv_query($conn,$sqls);
        if($data == true){
            while($rs = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) {
                  array_push($ArrDepartmentData,array("level"=>1,"id"=>$rs['vID'],"pid"=>$rs['vType'],"name"=>$rs['vtext'],"Order"=>$rs['vOrder']));
                  
            }
    }
    //$ArrDepartmentData=MultiLevelConvert2(MultiLevelConvert1($ArrDepartmentData,0),0);
    //组成多级数组
    function MultiLevelConvert1($arr,$id){
        $res = array();
        foreach ($arr as $key => $value) {
            if ($value["pid"] == $id) {
                $value["child"]=MultiLevelConvert1($arr,$value["id"]);
                array_push($res,$value);
            }
        }
        return $res;
    }
    //重新整理成一维数组
    function MultiLevelConvert2($arr,$level){
          $res = array();
          foreach ($arr as $key => $value) {
            if (count($value)>0) {
                $value["level"]=$level;
                if (count($value['child'])>0) {
                    $res2=MultiLevelConvert2($value['child'],$level+1);
                    array_pop($value);array_push($res,$value);
                    foreach ($res2 as $key => $value) {array_push($res,$value);}
                }
                else {array_pop($value);array_push($res,$value);}
            }
          }
          return $res;
    }
echo json_encode($ArrDepartmentData);
    
    //print_r($ArrDepartmentData);
    //echo json_encode($ArrDepartmentData);
 
    //foreach ($ArrDepartmentData as $value) {
    //    for($x=0;$x<$value["level"];$x++) {echo "--";}
    //    echo $value["name"].'<br>';
    //}
 
    ?>