Recursive call problems, online and other PHPcodefunctionshow_child ($ pid, $ layer = 0) {global $ db, $ reply_arr, $ layers, $ circle_reply, $ fid; if ($ layer & gt; = 5) // recursive call problems, online, etc.
PHP code
Function show_child ($ pid, $ layer = 0) {global $ db, $ reply_arr, $ layers, $ circle_reply, $ fid; if ($ layer> = 5) // recursive layers {return;} $ layer ++; foreach ($ reply_arr as $ k => $ v) {if ($ v ['reply'] = $ pid) {$ v ['message'] = discuzcode ($ v ['message'], $ replya ['smileyoff '], $ replya ['bbcodeoff'], $ replya ['htmlon'] & 1, 1, $ forum ['lowbbcode'], ($ forum ['allowimgcode'] & $ showimages? 1: 0), $ forum ['allowhtml '], ($ forum ['jammer'] & $ replya ['authorid']! = $ Discuz_uid? 1: 0), 0, $ replya ['authorid'], $ forum ['allowmediacode'], $ replya ['pid']); echo $ v ['message']. '| '. $ v ['pid '].'
'; Show_child ($ v ['pid']) ;}}
There is a function called recursively, and there is a loop in it, but after recursion, it should be because $ v is re-assigned, and the loop will no longer be done. How can Experts solve this problem?
------ Solution --------------------
Try adding a reset ($ reply_arr) before the loop,
In addition, your $ layer is in the parameter (but the call is useless) and global. it seems a bit inappropriate.
------ Solution --------------------
You can get show_child ($ v ['pid ']); and try it out if.
------ Solution --------------------
Do you mean to stop recursion on the fifth layer?
If yes, it can be implemented in this way.
If I understand it wrong, I will not be here.
PHP code
Function show_child ($ pid, $ layer = 0) {if ($ layer <5) {echo "current is the first". ($ layer + 1). "layer loop
\ N "; show_child ($ pid, ++ $ layer);} else {return false ;}}
------ Solution --------------------
Don't ask questions. you are the best person to solve the problem.
You can use the most complete php Tutorial ppt.
All problems encountered
Believe that you are the owner to solve the problem http: // http://www.itkanba.com/bbs/viewthread.php? Tid = 9508 & extra =
------ Solution --------------------
PHP code
Function show_child ($ pid, $ layer = 0) {global $ db, $ reply_arr, $ layers, $ circle_reply, $ fid; if ($ layer> = 5) // recursive layers {return;} $ layer ++; foreach ($ reply_arr as $ k => $ v) {if ($ v ['reply'] = $ pid) {echo $ v ['message']. '| '. $ v ['pid '].'
'; Show_child ($ v ['pid'], 7); // here, you want to stop this loop, and // add the second parameter that is more than 5 .}}}