Home  >  Article  >  Backend Development  >  php递归示例 php递归函数代码

php递归示例 php递归函数代码

WBOY
WBOYOriginal
2016-07-25 08:54:34949browse
  1. //递归获得角色ID字符串
  2. function explodeRole($roleObj, &$resultStr){
  3. if(0 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. //递归获取级联角色信息数组
  15. function makeRoleRelation(&$roleObjArr){
  16. foreach($roleObjArr as $item){
  17. $item->childRoleObjArr = getRoleObjArrByParentId($item->id);
  18. if(0 childRoleObjArr)){
  19. makeRoleRelation($item->childRoleObjArr);
  20. }
  21. }
  22. }
  23. //通过父角色的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. }
复制代码

>>> 您可能感兴趣的文章: php递归与迭代实现快速排序 php递归获取目录内文件(包含子目录)的代码 php无限级分类的递归函数 PHP递归打印数组中所有元素的简单示例代码 php递归遍历目录的二个函数 php自定义函数递归替换数组中的内容 php递归调用的小例子 有关PHP数组递归遍历的一点理解 php 数组递归求和的例子 php实现的无极分类(递归)的代码 php全排列的递归算法的代码



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]