function
Try it yourself →Defines a function.
Syntax
function name($p) { return value; }Description
Defined with function, called by name; takes parameters, returns a result with return.
Example
<?php
function square($x) {
return $x * $x;
}
echo square(5);Expected output
25
When to use?
Preventing code repetition.
Common mistakes
- ⚠️ If there is no return, the function returns NULL.