Home  >  Article  >  Backend Development  >  PHP introductory tutorial (7) PHP functions

PHP introductory tutorial (7) PHP functions

WBOY
WBOYOriginal
2016-07-25 08:55:461136browse
  1. function writeMyName()
  2. { // bbs.it-home.org
  3. echo "jeremyLin";
  4. }
  5. writeMyName();
  6. ? >
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:

  1. function writeMyName($fname)
  2. { // bbs.it-home.org
  3. echo $fname . "jeremy.
    ";
  4. }
  5. echo "My name is ";
  6. writeMyName("lin");
  7. echo "My name is ";
  8. writeMyName("kobe");
  9. echo "My name is ";
  10. writeMyName("John");
  11. ?>
Copy code

3. Function - return value Functions can also be used to return values.

  1. function add($x,$y)
  2. {
  3. $total = $x + $y;
  4. return $total;
  5. }
  6. echo "4 + 26 = " . add(4,26);
  7. ?>
Copy code

output: 4+26=30

>> View more php introductory tutorials



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn