1. Own functions
You can define a function with the reserved word “function”. You choose a name and you fill in the statements between the curly brackets.
The function can be called in a program by specifying the function name and two parentheses. You can call a function several times in different places in your program.
You don't have to specify a return value, but if you do then the result of the function can be used as a test value on the condition of a control structure (if, switch) or a loop structure (for, while). The function usually returns a boolean value (return false; or return true;). If the function returns a different value, you should of course test for the expected values (using the comparison operator ==).
A function can also contain one or more arguments. If the statements within the function e.g. If you expect 3 arguments and only 2 arguments are passed when the function is called, then the value of the third argument will be “null” (“nonexistent”, “nothing”).
With the PHP function isset($variable) you can check whether a variable exists or not.
As mentioned, the range of the variables is limited to the statements within the function. However, with the global statement you can give a variable a global scope (the variable is the same inside the function as outside it). However, this method is not recommended.
In the function definition you can assign start values to the arguments. This makes these arguments optional when calling the function. If you do enter a different value, this value will be used in the function.