Home > Backend Development > PHP Tutorial > PHP custom function returns multiple values, multiple php custom functions_PHP tutorial

PHP custom function returns multiple values, multiple php custom functions_PHP tutorial

WBOY
Release: 2016-07-12 09:03:35
Original
900 people have browsed it

PHP custom function returns multiple values, php custom function has multiple values

PHP custom function only allows return statement to return one value. When return is executed, the entire function The operation will terminate.

Sometimes when a function is required to return multiple values, return cannot be used to output the values ​​one after another.

One thing that cannot be ignored is that the return statement can return any type of variable. This is the key to making the custom function return multiple values.

Please see the code:

  1. //Custom function returns multiple values ​​
  2. function results($string)
  3. {
  4. $result = array();
  5. $result[] = $string;//Original string
  6. $result[] = strtoupper($string);//Change all to uppercase
  7. $result[] = strtolower($string);//Change all to lowercase
  8. $result[] = ucwords($string);//Change the first letter of the word to uppercase
  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 add the value that has been processed and is waiting for output to $result as an element, and finally output $result. This achieves the purpose of the custom function returning multiple values.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1080762.htmlTechArticlePHP custom function returns multiple values, php custom function multiple PHP custom functions only allow the return statement Return a value. When return is executed, the execution of the entire function will terminate. ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template