If you're looking for a way to save time when you program, look no further. Creating functions lets you reuse code that you've used before without having to rewrite the whole thing. Keep reading to learn how.
In the last section of this article we discuss functions that return a value. In the previous section we already touched on this kind of function. There are only two differences between the previous functions we discussed and functions that return a value. First, you use the return statement within the function. Second, you assign the result to a variable.
The syntax of a function that returns a value is something like this:
As with our randpass() function in earlier sections, to call a function that returns a value we do this:
$variable = function_name($argument);
Another example is:
return "Hello $argument!"
A user defined function usually returns just a single value, but it can also return more than one value when arrays are used. Here's a example of how it's done:
//your statements here
....and here's how you'd use the function.....
The $value1 from the function is assigned to $val1 and $value2 is assigned to $val2 and so forth.