Blogger Information
Blog 142
fans 5
comment 0
visits 130038
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php递归函数使用实例
php开发大牛
Original
821 people have browsed it

php递归使用示例(php递归函数),包括递归获得角色ID字符串、递归获取级联角色信息数组、通过父角色的id获取子角色信息。

例子:

代码示例:

//递归获得角色ID字符串
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);
}
}
}
//递归获取级联角色信息数组
function makeRoleRelation(&$roleObjArr){
foreach($roleObjArr as $item){
$item->childRoleObjArr = getRoleObjArrByParentId($item->id);
if(0 < count($item->childRoleObjArr)){
 makeRoleRelation($item->childRoleObjArr);
}
}
}
//通过父角色的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();
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post