PHP Custom functions return multiple values, PHP custom functions multiple _php Tutorials

Source: Internet
Author: User

PHP Custom function returns multiple values, PHP custom Function multiple


The PHP Custom function only allows you to return a value with a return statement, and when the return is executed, the entire function is terminated.

Sometimes when a function is required to return multiple values, it is not possible to output the value one by one, using return.

One thing to ignore is that the return statement can return any type of variable, which is the key to making the custom function return multiple values.

Please look at the code:

  1. Custom function returns multi-value
  2. function results ($string)
  3. {
  4. $result = Array ();
  5. $result [] = $string; Original string
  6. $result [] = strtoupper ($string); Replace All caps
  7. $result [] = strtolower ($string); Change all to lowercase
  8. $result [] = Ucwords ($string); Capitalize the first letter of a word
  9. return $result;
  10. }
  11. $multi _result = results (' The quick brown fox jump over the Lazy dog ');
  12. Print_r ($multi _result);
  13. ?>
Output Result:
Array
(
[0] = The quick brown fox jump over the lazy dog
[1] = the QUICK BROWN FOX jump over the LAZY DOG
[2] = The quick brown fox jump over the lazy dog
[3] = the Quick Brown Fox jump over the Lazy Dog
)
The above code creates a $result array, then adds the processed and waiting output values to $result as an element, and finally outputs the $result, which enables the custom function to return multiple values.

http://www.bkjia.com/PHPjc/1080762.html www.bkjia.com true http://www.bkjia.com/PHPjc/1080762.html techarticle PHP Custom Functions return multiple values, PHP custom functions multiple PHP custom functions only allow return of a value with the return statement, and when the return is executed, the entire function is terminated. ...

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