1. Defining and Calling Functions
A function is a self-contained block of statements designed to perform a distinct task. Functions enhance code reusability, modularity, and testing.
2. Function Arguments and Default Parameters
You can provide default values for parameters, making them optional when calling the function:
3. Pass by Value vs Pass by Reference
By default, function arguments are passed by value (a copy of the variable is created). To modify the original variable directly, prepend an ampersand (&) to the parameter declaration:
4. Type Hinting and Return Type Declarations
Starting with modern PHP 7 and 8, you can enforce strict type safety for parameters and return values:
5. Anonymous Functions and Arrow Functions
$amount + ($amount * $taxRate);
echo $calculateTotal(100); // 118