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 we ask the function to return multiple values, it is not possible to output the value one by one by return. It is important to note 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:
function results ($string)
{
$result = Array ();
$result [] = $string;//Original string
$result [] = Strtoupper ($string);//convert All to uppercase
$result [] = Strtolower ($string);//convert All to lowercase
$result [] = Ucwords ($string);//The first letter of the word is changed to uppercase
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/317208.html www.bkjia.com true http://www.bkjia.com/PHPjc/317208.html techarticle 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 we ask for a function to return multiple values, return is not ...