Php functions and passing parameters. This tutorial introduces the function call and function definition syntax, and describes the variables in the function and the numerical method for passing values to the function. This tutorial will introduce the call and determination of functions. This tutorial will introduce the call and definition syntax of functions, as well as the variables in functions and the method for passing numeric values to functions.
This tutorial introduces the function call and function definition syntax, and describes the variables in the function and the numerical method for passing values to the function.
I. Basics of functions
The php Tutorial provides a large number of functions and allows you to customize the functions,
Php function definition instance
Function myCount ($ inValue1, $ inValue2)
{
$ AddValue = $ inValue1 + $ inValue2;
Return $ AddValue; // return the calculation result
}
$ Count = myCount (59,100 );
Echo $ Count; // output 159
?>
Functions can be used anywhere once defined.
II. function parameters
Php functionsWhen defining a function, a parameter is defined. a function can have any number of parameters. The most common transfer method is passed by value. Or the application by reference and default parameter values is relatively small.
Instance
Function myColor ($ inColor = "blue ")
{
Return "my favorite colors: $ inColor. n ";
}
Echo myColor ();
Echo myColor ("pink ");
?>
Generally, the passed value is not changed because of internal changes in the function. Unless it is a global variable or reference.Php functionsReference instance
Function str_unite (& $ string)
{
$ String. = 'also like blue .';
}
$ Str = 'like red ,';
Str_unite ($ str );
Echo $ str; // output result: 'Like red or blue .'
?>
Global variables
$ A = 1;
$ B = 2;
Function Sum ()
{
Global $ a, $ B;
$ B = $ a + $ B;
}
Sum ();
Echo $ B;
?>
Bytes. This tutorial introduces how to call and define functions...