Php recursive example php recursive function code
- // 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 ();
- }
>>> Articles you may be interested in: php recursive and iterative implementation of quick sorting php recursive retrieval of files in the Directory (including subdirectories) php infinite classification recursive function PHP recursive print simple example code of all elements in the array php recursive traversal directory two functions php user-defined function recursive replacement array content php recursive call A small example of PHP array recursive traversal an example of php array recursive summation an example of php's promise classification (recursion) php code of a fully-arranged recursive algorithm |