您好,欢迎访问一九零五行业门户网

php递归使用示例(php递归函数)_PHP教程

//递归获得角色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();}
php的递归函数用法
一个函数在它的函数体内调用它自身称为递归调用。这种函数称为递归函数。这对于程序员来说,通常有很高的实用价值,常用来将复杂的问题分解为简单的并相同的情况,反复做这种处理直到问题解决。
用递归函数与不用递归函数的区别
示例一:使用静态变量
function test(){ static $dig=0; if($dig++<?phpfunction reverse_i($str){for($i=1;$i<=strlen($str);$i++){echo substr($str,-$i,1);}}
这个程序清单中实现两个函数,这两个函数都可以相反的顺序打印字符串的内容
函数reversr_r是通过递归实现的,而函数reverse_i()是通过循环实现的
http://www.bkjia.com/phpjc/825220.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/825220.htmltecharticle//递归获得角色id字符串function exploderole($roleobj, lt; count($roleobj-childroleobjarr)){ foreach($roleobj-childroleobjarr as $childroleobj){ if('' == $resultstr){ $resul...
其它类似信息

推荐信息