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:
-
- Custom function returns multi-value
- function results ($string)
- {
- $result = Array ();
- $result [] = $string; Original string
- $result [] = strtoupper ($string); Replace All caps
- $result [] = strtolower ($string); Change all to lowercase
- $result [] = Ucwords ($string); Capitalize the first letter of a word
- return $result;
- }
- $multi _result = results (' The quick brown fox jump over the Lazy dog ');
- Print_r ($multi _result);
- ?>
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. ...