In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what is the meaning of the return value in php". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In PHP, the return value is the result value that takes the result of the function operation from the inside of the function. By using the optional return statement, the return value can return any type, including arrays and objects. The return statement immediately aborts the function and returns control to the line of code that called the function.
This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.
What does the return value in php mean?
What is the return value of the php function? In PHP, the return value of a function can be any type of data; of course, the function can not return a value. The function returns data using the return keyword, and the function terminates execution immediately when it encounters the return keyword.
The sample code is as follows:
Function square ($num) {return $num * $num;} echo square (4); / / outputs'16'.? >
What is the return value of the php function? The running result of the above code is:
sixteen
A function can only have one return value
Functions cannot return multiple values, but you can achieve a similar effect by returning an array. The code is as follows:
The result of code execution is:
Function small_numbers () {return array (0,1,2);} list ($zero, $one, $two) = small_numbers (); echo $zero. $one. $two;? > 012
The values of $zero $one $two are 0, 1, and 2, respectively.
Return value type declaration
What is the return value of the php function? In PHP 7, the function added the type declaration of the return value. Similar to the parameter type declaration, in non-strict mode, PHP will try to convert the return value type to the expected value type, but in strict mode, the return value of the function must be consistent with the declared return type.
Examples are as follows:
Function sum ($a, $b): float {return $a + $b;} var_dump (sum (1Magne2));? >
The above program will output:
Float (3)
The code in strict mode is as follows:
Declare (strict_types=1); function sum ($a, $b): int {return $a + $b;} var_dump (sum (1)); var_dump (sum (1));? >
The value is returned by using an optional return statement. You can return any type that includes arrays and objects. The return statement immediately aborts the function and returns control to the line of code that called the function.
A function is a collection of functions. Perform certain functions or operations. It is meaningless for the result after the operation to remain inside the function. The return value is to take the result of the function operation out of the function. Whether it is a custom function or a built-in function. The prototypes are as follows:
Function function name (parameter 1, parameter 2...) {Operation process return operation result;}
The function of the return keyword is to remove the result of the operation from the inside of the function. To get this value. You can assign a value to a variable using the = sign.
$var = function name (parameter, if any)
The operation result inside the function can be obtained by $var. There are also some functions that have no return value. Like var_dump.
Pay special attention. Return value. It just returns the "value" of the result of the operation, not a specific variable. For example:
Funciton test () {$a = 1room2scape return $a;}
The above code returns a value of 3. Not $an itself. That's why it's called returning "value."
This is the end of the content of "what is the meaning of the return value in php". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.