PHP user-defined functions return multiple values, and php user-defined functions return multiple values. PHP user-defined functions return multiple values. php user-defined functions allow only one value to be returned using the return statement. after the return statement is executed, the entire function is terminated. PHP user-defined functions return multiple values, and php user-defined functions return multiple values.
PHP user-defined functions can only return a value using the return statement. after the return statement is executed, the entire function is terminated.
When a function is required to return multiple values, return cannot be used to output values one by one.
It cannot be ignored that the return statement can return any type of variables, which is the key to making the UDF return multiple values.
See the code:
-
- // The user-defined function returns multiple values.
- Function results ($ string)
- {
- $ Result = array ();
- $ Result [] = $ string; // original string
- $ Result [] = strtoupper ($ string); // replace all with uppercase letters
- $ Result [] = strtolower ($ string); // replace all with lowercase letters
- $ Result [] = ucwords ($ string); // replace the first letter of a word with an uppercase letter.
-
-
- 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 code above creates an $ result array, adds the processed and output values to $ result as an element, and outputs $ result, in this way, the user-defined function returns multiple values.
Except PHP user-defined functions can only return one value using the return statement. after the return statement is executed, the operation of the entire function will be terminated ....