This article mainly introduces the PHP recursive use example (PHP recursive function), including recursive get role ID string, recursive get Cascade role information array, through the parent role ID to get child role information, need friends can refer to the following
The code is as follows://recursively get role ID string function Exploderole ($ROLEOBJ, & $resultStr) { if (0 < count ($roleObj-> Childroleobjarr)) { foreach ($roleObj->childroleobjarr as $CHILDROLEOBJ) { & nbsp if (' = = $resultStr] { $resultStr. = "{$childR Oleobj->id} "; }else{ $resultStr. = ", {$CHILDROLEOBJ->id} "; Exploderole ($CHILDROLEOBJ, $resultSt R); } }} //Recursive get Cascade role information Array function makerolerelation (& $ROLEOBJARR) { foreach ($roleObjArr as $item) { $item->childroleobjarr = Getroleobjarrbyparentid ($ ITEM->ID); if (0 < count ($item->childroleobjarr)) { &NBSp makerolerelation ($item->childroleobjarr); } }} //Get child role information through ID of parent role function Getroleobjarrbyparentid ($pa Rentid) { $operCOGPSTRTSysRole = new Cogpstrtsysrole () $operCOGPSTRTSysRole->setcolumn ($ Opercogpstrtsysrole->getallcolumn ()); $operCOGPSTRTSysRole->setwhere ("parentroleid={$parentid}"); $ROLEOBJARR = $operCOGPSTRTSysRole->convresult2objarr ($operCOGPSTRTSysRole->selecttable ()); return isset ($ROLEOBJARR) $ROLEOBJARR: Array (); }