The return value of the php function. In fact, the php function can return one or more values. you can use the return keyword to return a variable or an array. Return will stop the program at return and return the specified variable.
Php function return value. in fact, the php function can return one or more values. you can use the return keyword to return a variable or an array. return will stop the program at return and return the specified variable. let's take an example today:
The instance code is as follows:
- ';
- Function she ($ a, $ B, $ c)
- {
- Return array ($ c, $ B, $ );
- }
- List ($ x, $ y, $ z) = she (2, 3, 4 );
- Echo '$ x ='. $ x. '$ y ='. $ y. '$ z ='. $ z;
- ?>
- The execution result is as follows:
-
- Function add ($ shu)
- {
- Return $ shu + 1;
- }
- Echo add (2 ).'
- ';
- Function she ($ a, $ B, $ c)
- {
- Return array ($ c, $ B, $ );
- }
- List ($ x, $ y, $ z) = she (2, 3, 4 );
- Echo '$ x ='. $ x .'
- $ Y = '. $ y .'
- $ Z = '. $ z;
- ?>
Php function, how to return multiple return values? (the function cannot return multiple values, but you can return an array to obtain similar results .)
The instance code is as follows:
-
- Function results ($ string)
- {
- $ Result = array ();
- $ Result [] = $ string; // original string
- $ Result [] = strtoupper ($ string); // replace all with uppercase letters
- $ Result [] = strtolower ($ string); // replace all with lowercase letters
- $ Result [] = ucwords ($ string); // replace the first letter of a word with an uppercase letter.
- 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
- )
Reference: This function returns three values. one is the function return and the other two are referenced.
The instance code is as follows:
- Test (& $ a, & $ B ){
- $ A = 1000;
- $ B = 12000;
- Return $ a + $ B;
- }
- $ A = 10;
- $ B = 12;
- $ C = test ($ a, $ B); // note that no & is found here.
- // Display the modified value
- Echo $;
- Echo $ B;
- Echo $ c; // This is the return value of the function;