-
-
-
- function writeMyName()
- { // bbs.it-home.org
- echo "jeremyLin";
- }
- writeMyName();
- ? >
-
-
Copy code
2, function - add parameters
The first function is a very simple function.
It can only output a static string.
Add more functionality to the function by adding parameters. A parameter is like a variable.
example:
-
-
-
- function writeMyName($fname)
- { // bbs.it-home.org
- echo $fname . "jeremy.
";
- }
-
- echo "My name is ";
- writeMyName("lin");
-
- echo "My name is ";
- writeMyName("kobe");
-
- echo "My name is ";
- writeMyName("John");
- ?>
-
-
Copy code
3. Function - return value
Functions can also be used to return values.
-
-
-
- function add($x,$y)
- {
- $total = $x + $y;
- return $total;
- }
-
- echo "4 + 26 = " . add(4,26);
- ?>
-
Copy code
output:
4+26=30
>> View more php introductory tutorials
|