💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
>[info] 无限极循环找出部门的子部门 1. 引入部门管理类 ~~~ use Easydingtalk\Department; ~~~ 2. 代码: ~~~ if (!function_exists('getDepts')) { // 无限极循环找出部门的子部门 function getDepts($dept_id) { // 获取所有部门 $result = json_decode(Department::listsub($dept_id), true)['result']; // 是否终止标识 $break = false; // 结果集为空 if (empty($result)) { $break = true; } // 判断标识 if (!$break) { for ($p = 0; $p < count($result); $p++) { $result[$p]['subs'] = getDepts($result[$p]['dept_id']); } } // 返回 return $result; } } ~~~ 3. 调用示例: ~~~ // 打印结果 dump(getDepts(1)); ~~~ 4. 返回: ``` [ { "auto_add_user": false, "create_dept_group": false, "dept_id": 709636861, "name": "下级部门1", "parent_id": 1, "subs": [ { "auto_add_user": true, "create_dept_group": true, "dept_id": 808533310, "name": "下级部门1_1", "parent_id": 709636861, "subs": [ { "auto_add_user": true, "create_dept_group": true, "dept_id": 808012923, "name": "下级部门1_1_1", "parent_id": 808533310, "subs": [] } ] } ] }, { "auto_add_user": true, "create_dept_group": true, "dept_id": 721279636, "name": "下级部门2", "parent_id": 1, "subs": [] }, { "auto_add_user": false, "create_dept_group": false, "dept_id": 808357313, "name": "下级部门3", "parent_id": 1, "subs": [] } ] ```