In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how many php function return values are there". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how many php function return values are there" can help you solve the problem.
The php function can return only one value. In PHP, the function return value is defined using the return statement, with the syntax "return return value;". The return statement can return only one parameter, that is, the function can only have one return value; if you want to return more than one value, you need to define an array in the function and store the return value in the array.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The php function can return only one value.
A function is a collection of functions that can implement some specific functions or operations. It makes no sense to keep the result of the function inside the function after running, so we need to return the result of the function to the place where the function is called.
The return statement is provided in PHP to return the running result of the function. The syntax format is as follows:
Return return value
Where the return value is an optional parameter, which can be a specific value or expression, or empty. The return value and the return keyword need to be separated by a space.
The running result of the above code is:
sixteen
Note: a function can only have one return value.
The return statement can return only one parameter, that is, only one value, not more than one value at a time. If you want to return more than one value, you need to define an array in the function and store the return value in the array.
Note the following when using return statements:
The return statement is used to return a value to the "caller of the function". After returning the value, the function runs immediately, so the return statement is usually placed at the end of the function.
If there is more than one return statement in a function, only the first one is executed
The return statement can also return no parameters, which is equivalent to ending the run of the function
If you use the return statement in the global scope, the currently running script is terminated immediately
If a script file introduced using include or require contains a return statement, it returns to the place where the script was introduced to continue execution, and the rest of the code after return is no longer executed.
[example] the following implements a function to calculate the exchange rate, and returns the calculated value through return, as shown in the following code:
The running results are as follows:
50 yuan RMB = 7.19 US dollars
Tip: in the above example, we use return in the function to return a variable $price, which is not the variable itself, but the value of the variable. So outside the function, we need to use another variable to store this value.
From the above introduction, we know that return can only return one parameter at a time. If you want to return more than one parameter, you need to use an array. Let's demonstrate it through an example:
The result of code execution is:
012
The values of $zero $one $two are 0, 1, and 2, respectively.
This is the end of the content about "how many php function return values". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.