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