In PHP, programmers are allowed to organize components such as commonly used processes or variables into a fixed format. That is, users can assemble functions or classes themselves.
Functions in PHP, like the C language, include return value and no return value , not as complex as Pascal partitioning functions (function) and programs (procedure).
On the name of the function, PHP is loosely controlled for capitalization. You can write a capital name when you define a function, and use a lowercase name when you use it. In short, for functions, regardless of the case, as long as the attention of the name does not repeat the good.
Here is the syntax for using the function
function MyFunc ($arg _1, $arg _2, ..., $arg _n) {
Perform some steps
return $retval;
}
When used, the reserved word of a function is added before the custom function name, which means that it defines a user-defined function. After the myfunc can be any letter at the beginning of the string, the string except the beginning can not be a number or underscore, after the first letter can be Arabic numerals or underscores, of course, other symbols or Chinese characters can not be used as function names.
$arg _1 to $arg _n the parameters used by the function, separated by commas. The curly brace {} After the argument is the part of the entire function. function returns a value if the value is returned by using return. Parameters can define initial or default values beforehand. A defined default value parameter can be omitted when using a function, but it must be placed after the default value parameter is not configured, otherwise PHP will have an error parsing the function.
The other is the type of parameter, as long as the parameter is a variable type supported by PHP, whether it is an array, a string, or an integer .... Wait a minute. The return value is the same.
The following is an example of using default values and default values
<?php
function myfunc1 ($arg _1, $arg _2, $arg _3= "I am the default string") {
echo $arg _1+ $arg _2;
echo $arg _3. " <p>\n ";
}
MyFunc (3, 4); Parameter $arg _3 omitted.
MyFunc (6, 6, "No default Value")//input parameter $arg _3.
?>
The value of the parameter, which is usually entered using a method, and sometimes a pointer to a parameter can be passed in by using the address in the way that is worth it. The method is to precede the parameter with the & symbol.