Home  >  Article  >  Backend Development  >  The format of function definition in php

The format of function definition in php

藏色散人
藏色散人Original
2019-10-21 10:00:255417browse

The format of function definition in php

The format of function definition in php

Function is a function. Encapsulate a piece of code that performs a specific function. Calling a function is calling a function.

Custom function

function generate_table($row, $col){
$html = &#39;<table>&#39;;
for ($i = 1; $i <= $row; ++$i) {
      $html .= &#39;<tr>&#39;;
           for ($j = 1; $j <= $col; ++$j){
               $html .= &#39;<td></td>&#39;;
        }
         $html .= &#39;</tr>&#39;;
}
   return $html.&#39;</table>&#39;;
}
echo generate_table(5,5);

The above is to use a custom function to define the table generator as a function.

Basic syntax format of function

function 函数名([参数1, 参数2, ……]){
    函数体……
}

function: Keywords that must be used when declaring a function

Function name: Identifier that must comply with PHP , and the function name is unique and case-insensitive

[Parameter 1, Parameter 2...]: The value passed to the function from the outside world, it is optional, use commas "," between multiple parameters Separate.

Function body: The main body of the function definition, a code segment specifically used to implement specific functions.

Return value: You need to use the return keyword to pass the data that needs to be returned to the caller.

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of The format of function definition in php. For more information, please follow other related articles on the PHP Chinese website!

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
Previous article:Is php very inefficient?Next article:Is php very inefficient?