Recursive call problems

Source: Internet
Author: User
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 .}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.