The keyword for defining functions in PHP is function. It specifies the function name, parameter list and function body: function function name (parameter list): defines the function name and parameters. {}: The function body contains the code to be executed. return: optional, returns the value of the function.
The keywords that define functions in php
The keywords that define functions in php arefunction.
Syntax
<code class="php">function 函数名 (参数列表) { // 函数体 }</code>
Example
Define a function named sum
for calculation The sum of two numbers:
<code class="php">function sum(int $num1, int $num2) { return $num1 + $num2; }</code>
Parameter list
Function body
return
statement to return a value. The above is the detailed content of What characters are the keywords used to define functions in PHP?. For more information, please follow other related articles on the PHP Chinese website!