This article source: http://www.zretc.com/technologyDetail/442.html
To get started with php, the function is a must-have, and here's what you need to know:
Definition of a function
function definition
Function name ([parameter 1, parameter 2, parameter 3, ...] ){
function body;
[return value;]
}
Function call
Function name ([parameter 1, parameter 2, parameter 3, ...] );
For example:
define function sum
Functionsum ($a, $b) {
$sum _value= $a + $b;
return$sum_value;
}
Call function sum
Sum (100,300);
Description
1.function: Define PHP function keywords;
2.sum: Name of function;
3. $a, $b: parameters;
4.return: return worth keyword ($sum _value return value);
second, variable function
The so-called mutable function, that is, the function is called by the value of the variable, because the value of the variable is variable, so you can call different functions by changing the value of a variable. Often used in callback functions, function lists, or depending on dynamic parameters to invoke different functions. The variable function is called by the variable name in Parentheses.
Function name () {
Echo ' Jobs ';
}
$func = ' name ';
$func (); Calling a mutable function
three, built-in functions
Built-in functions refer to Php's Default supported functions, and PHP contains a number of standard common processing functions, including string processing, array functions, file handling, session and Cookie Processing.
For example, a string substitution can be implemented by using the built-in function str_replace. The following example replaces "jobs" with "steven jobs":
$str = ' I am jobs ';
$str = str_replace (' jobs ', ' steven Jobs ', $str);
Echo $str; The result is "i am Steven jobs"
Iv. determining whether a function exists
1.function_exists determine if a function exists
Functionfunc () {
}
If (function_exists (' func ')) {
Echo ' exists ';
}
2.method_exists the existence of a method of judging a class
3.class_exists to determine whether a class exists
classmyclass{
}
Check if class exists before use
If (class_exists (' MyClass ')) {
$myclass = new MyClass ();
}
4.file_exists determine if a file exists
$filename = ' Test.txt ';
If (!file_exists ($filename)) {
Echo$filename. ' Not Exists. ';
}
Learn more about getting started with PHP learn more in the soft International education Group Technical Knowledge base!
PHP Introductory Learning--function Chapter