PHP function return value _php tutorial

Source: Internet
Author: User
The return value of the PHP function. In fact, the PHP function can return one or more values, using the return keyword can return a variable or an array. Return causes the program to stop at return and returns the specified variable.

Give me an example today:

The code is as follows Copy Code

';
Function She ($a, $b, $c)
{
Return Array ($c, $b, $a);
}
List ($x, $y, $z) =she (2,3,4);
echo ' $x = '. $x. ' $y = '. $y. ' $z = '. $z;
?>
Execution results such as:

function Add ($shu)
{
return $shu +1;
}
echo Add (2). '
‘;

Function She ($a, $b, $c)
{
Return Array ($c, $b, $a);
}
List ($x, $y, $z) =she (2,3,4);
echo ' $x = '. $x. '
$y = '. $y. '
$z = '. $z;
?>

PHP Letter

Number, you want to return multiple returned values, how to do it (the function cannot return multiple values, but you can get a similar effect by returning an array.)

code as follows copy code

"!--? php
function results ($stri ng)
{
$result = array ();
$result [] = $string;//original String
$result [] = Strtoupper ($string);//all uppercase
$result [] = Strtolower ($string);// Change all to lowercase
$result [] = Ucwords ($string);//The first letter of the word is replaced by uppercase

Return $result;
}
$multi _result = results (' The quick brown fox jump over the Lazy dog ');
Print_r ($multi _result);
?

Output:
Array
(
[0] = The quick brown fox jump over the lazy dog
[1] = The quick brown fox Jump O VER the Lazy dog
[2] = The quick brown fox jump over the lazy dog
[3] = The quick brown fox jump over the Lazy Dog
)

Reference

This function returns three values, one for the function return, and two for a reference.

The code is as follows Copy Code

Test (& $a,& $b) {
$a = 1000;
$b = 12000;
return $a + $b;
}

$a = 10;
$b = 12;

$c = Test ($a, $b); Notice there's no & here.

Display the modified value
echo $a;
Echo $b;
Echo $c; This is the function return value;

http://www.bkjia.com/PHPjc/629017.html www.bkjia.com true http://www.bkjia.com/PHPjc/629017.html techarticle The return value of the PHP function. In fact, the PHP function can return one or more values, using the return keyword can return a variable or an array. Return causes the program to stop at return and return to ...

  • 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.