When should we use return?

Source: Internet
Author: User
Never understand the use of return when should be used when should not use who can tell?
Why add return to the following example?


  
   money*0.8;   } }$a=new man();echo $a->show();?>

Reply content:

Never understand the use of return when should be used when should not use who can tell?
Why add return to the following example?


  
   money*0.8;   } }$a=new man();echo $a->show();?>

returnis to return a result to the caller of the function/method.

For instance, your example calls the show() method to return an integer (800). The place to call is the equivalent of execution echo 800 .

If your function/method is to perform some operation instead of returning data, you can return a Boolean value to indicate whether the operation succeeded or failed for process control where it was called.

Return what, your function is running out of what, if not return your function is empty after running
For example, function A () {return 1;}
Execute a () to get 1
$b = A (); Then $b is equal to 1, if not return then execute a () there is no return value, that is, empty, that $b is empty

  • 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.