This article mainly introduces php recursive examples (php recursive functions), including recursively obtaining the role ID string, recursively obtaining the cascade role information array, and obtaining the subrole information through the parent role id, for more information, see
This article mainly introduces php recursive examples (php recursive functions), including recursively obtaining the role ID string, recursively obtaining the cascade role information array, and obtaining the subrole information through the parent role id, for more information, see
The Code is as follows:
// Recursively obtain the role ID string
Function explodeRole ($ roleObj, & $ resultStr ){
If (0 <count ($ roleObj-> childRoleObjArr )){
Foreach ($ roleObj-> childRoleObjArr as $ childRoleObj ){
If (''= $ resultStr ){
$ ResultStr. = "{$ childRoleObj-> id }";
} Else {
$ ResultStr. = ", {$ childRoleObj-> id }";
}
ExplodeRole ($ childRoleObj, $ resultStr );
}
}
}
// Recursively retrieve the cascade role information array
Function makeRoleRelation (& $ roleObjArr ){
Foreach ($ roleObjArr as $ item ){
$ Item-> childRoleObjArr = getRoleObjArrByParentId ($ item-> id );
If (0 <count ($ item-> childRoleObjArr )){
MakeRoleRelation ($ item-> childRoleObjArr );
}
}
}
// Obtain the sub-role information through the parent role id
Function getRoleObjArrByParentId ($ parentid ){
$ OperCOGPSTRTSysRole = new COGPSTRTSysRole ();
$ OperCOGPSTRTSysRole-> setColumn ($ operCOGPSTRTSysRole-> getAllColumn ());
$ OperCOGPSTRTSysRole-> setWhere ("parentroleid = {$ parentid }");
$ RoleObjArr = $ operCOGPSTRTSysRole-> convResult2ObjArr ($ operCOGPSTRTSysRole-> selectTable ());
Return isset ($ roleObjArr )? $ RoleObjArr: array ();
}
,