Home >Backend Development >PHP Problem >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 = '<table>'; for ($i = 1; $i <= $row; ++$i) { $html .= '<tr>'; for ($j = 1; $j <= $col; ++$j){ $html .= '<td></td>'; } $html .= '</tr>'; } return $html.'</table>'; } 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!