Php recursive example php recursive function code

Source: Internet
Author: User
Php recursive example php recursive function code

  1. // Recursively obtain the role ID string
  2. Function explodeRole ($ roleObj, & $ resultStr ){
  3. If (0 <count ($ roleObj-> childRoleObjArr )){
  4. Foreach ($ roleObj-> childRoleObjArr as $ childRoleObj ){
  5. If (''= $ resultStr ){
  6. $ ResultStr. = "{$ childRoleObj-> id }";
  7. } Else {
  8. $ ResultStr. = ", {$ childRoleObj-> id }";
  9. }
  10. ExplodeRole ($ childRoleObj, $ resultStr );
  11. }
  12. }
  13. }
  14. // Recursively retrieve the cascade role information array
  15. Function makeRoleRelation (& $ roleObjArr ){
  16. Foreach ($ roleObjArr as $ item ){
  17. $ Item-> childRoleObjArr = getRoleObjArrByParentId ($ item-> id );
  18. If (0 <count ($ item-> childRoleObjArr )){
  19. MakeRoleRelation ($ item-> childRoleObjArr );
  20. }
  21. }
  22. }
  23. // Obtain the sub-role information through the parent role id
  24. Function getRoleObjArrByParentId ($ parentid ){
  25. $ OperCOGPSTRTSysRole = new COGPSTRTSysRole ();
  26. $ OperCOGPSTRTSysRole-> setColumn ($ operCOGPSTRTSysRole-> getAllColumn ());
  27. $ OperCOGPSTRTSysRole-> setWhere ("parentroleid = {$ parentid }");
  28. $ RoleObjArr = $ operCOGPSTRTSysRole-> convResult2ObjArr ($ operCOGPSTRTSysRole-> selectTable ());
  29. Return isset ($ roleObjArr )? $ RoleObjArr: array ();
  30. }

>>> 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.