PHP Recursive sample PHP recursive function code

Source: Internet
Author: User
  1. Get the role ID string recursively
  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. Recursive get 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. Get child role information through the ID of the parent role
  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. }
Copy Code

>>> articles you may be interested in: PHP recursive and iterative implementation Quick sort PHP Recursive get directory files (contains subdirectories) Code PHP infinite class recursive function PHP recursively print a simple example code for all elements of an array PHP recursively traverse the directory of two functions PHP custom function recursively replace the contents of the array php a little example of a recursive recursive call to PHP for recursive traversal Example of recursive summation of arrays PHP implementation of the Infinite Classification (recursive) Code of PHP full permutation of the 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.