Make PHP Custom functions return multiple values _php tips
Source: Internet
Author: User
The PHP Custom function only allows returns a value with the return statement, and the entire function is terminated when it is executed. Sometimes when we ask a function to return more than one value, you can't output the value one after the other by returning. But the point to be reckoned with is that the return statement returns any type of variable, which is the key to making the custom function return multiple values. Please look at the code:
<?php
function results ($string)
{
$result = Array ();
$result [] = $string;//Original string
$result [] = Strtoupper ($string);//All uppercase
$result [] = Strtolower ($string);//All lowercase
$result [] = Ucwords ($string);//The first letter of the word is capitalized
return $result;
}
$multi _result = results (' The quick brown fox jump over the Lazy dog ');
Print_r ($multi _result);
?>
Output results:
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 a $result array, and then adds the processed and waiting values to the $result as an element and finally $result the output, which enables the custom function to return multiple values.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service