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:
-
- function results($string)
- {
- $result = array();
- $result[] = $string;
- $result[] = strtoupper($string);
- $result[] = strtolower($string);
- $result[] = ucwords($string);
-
-
- 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 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.
http://www.bkjia.com/PHPjc/1080762.htmlwww.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. ...