Make PHP Custom functions return multiple values _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.