Recursive get Role ID string function Exploderole ($ROLEOBJ, & $resultStr) {if (0 < count ($roleObj->childroleobjarr)) {Fore Ach ($roleObj->childroleobjarr as $CHILDROLEOBJ) {if ("= = $resultStr) {$resultStr. =" {$CHILDROLEOBJ->
ID} ";
}else{$resultStr. = ", {$childRoleObj->id}";
} exploderole ($CHILDROLEOBJ, $RESULTSTR); The Cascade role Information Array function makerolerelation (& $ROLEOBJARR) {foreach ($roleObjArr as $item) {$item->childr
Oleobjarr = Getroleobjarrbyparentid ($item->id);
if (0 < count ($item->childroleobjarr)) {makerolerelation ($item->childroleobjarr);
The ID of the parent role gets the child role information function Getroleobjarrbyparentid ($parentid) {$operCOGPSTRTSysRole = new cogpstrtsysrole ();
$operCOGPSTRTSysRole->setcolumn ($operCOGPSTRTSysRole->getallcolumn ());
$operCOGPSTRTSysRole->setwhere ("parentroleid={$parentid}"); $ROLEOBJARR = $operCOGPSTRTSysRole->convresult2objarr ($operCOGPSTRTSysRole->seLecttable ());
return Isset ($ROLEOBJARR)? $ROLEOBJARR: Array ();
}
Recursive function usage in PHP
A function calls itself in its function body called a recursive call. This function is called a recursive function. This is usually a very high practical value for programmers, and is often used to decompose complex problems into simple and identical situations, repeatedly doing this until the problem is solved.
The difference between recursive function and no recursive function
Example one: using static variables
function test () {
static $dig =0;
if ($dig ++<10) {
echo $dig;
Test ();
}
}
Test ();//12345678910
Example two: Using recursive functions and loops to implement string reversal arrangements
function Unreverse ($str) {
for ($i =1; $i <=strlen ($STR); $i + +) {
echo substr ($str,-$i, 1);
}
}
Unreverse ("ABCDEFG");//GFEDCBC
function Reverse ($str) {
if (strlen ($STR) >0) {
reverse (substr ($ str,1));
Echo substr ($STR, 0,1);
return;
}
Reverse ("ABCDEFG");//GFEDCBC
Recursive functions we can iterate over many times, and suggest that we reuse them when we can't use loops instead, because we're easier to understand with loops, and less prone to error.
PHP recursive function PHP to pay recursive functions, recursive function is to call themselves, these functions are particularly suitable for browsing dynamic data structures, such as trees and lists.
Almost no web application requires complex data structures to be used
<?php
function Reversr_r ($str)
{
if (strlen ($STR) >0)
Reverse_r (substr ($STR, 1));
Echo substr ($STR, 0,1);
return;
>
<?php
function reverse_i ($str)
{for
($i =1; $i <=strlen ($STR); $i + +)
{
echo SUBSTR ($str,-$i, 1);
}
This list of programs implements two functions, both of which can print the contents of the string in the opposite order
Function Reversr_r are implemented recursively, and function reverse_i () is implemented through loops