Home > php教程 > php手册 > body text

php递归使用示例(php递归函数)

WBOY
Release: 2016-06-06 20:24:52
Original
1001 people have browsed it

这篇文章主要介绍了php递归使用示例(php递归函数),包括递归获得角色ID字符串、递归获取级联角色信息数组、通过父角色的id获取子角色信息,需要的朋友可以参考下

复制代码 代码如下:


//递归获得角色ID字符串
function explodeRole($roleObj, &$resultStr){
    if(0 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 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();
}

Related labels:
source:php.cn
Statement of this Website
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 admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!