Solutions to problems with PHP recursive return values _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Solutions for PHP recursive return values. We are using this to start writing :? Phpfunctiontest ($ I) {$ I-4; if ($ i3) {return $ I;} else {test ($ I) ;}} echotest (30 );? This code looks okay. In fact, we are using e.This is the beginning of writing:

  1. <? Php
  2. Function test ($ I)
  3. {
  4. $ I-= 4;
  5. If ($ I< 3)
  6. {
  7. Return $ I;
  8. }
  9. Else
  10. {
  11. Test ($ I );
  12. }
  13. }
  14. Echo test (30 );
  15. ?>

This code seems to be okay. In fact, there is a problem in else. The test executed here does not return a value. Therefore, even if the condition $ I <3 is met, the return $ I function does not return a value. The above PHP recursive return value function is modified as follows:

 
  1. <? Php
  2. Function test ($ I)
  3. {
  4. $ I-= 4;
  5. If ($ I <3)
  6. {
  7. Return $ I;
  8. }
  9. Else
  10. {
  11. Return test ($ I); // add return to let the function return values.
  12. }
  13. }
  14. Echo test (30 );
  15. ?>

The above code example is the specific solution to the problem of PHP recursive return values.


Begin :? Php functiontest ($ I) {$ I-= 4; if ($ I 3) {return $ I;} else {test ($ I );}} echotest (30 );? This code seems to be okay. In fact, there are e...

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.