18. Function Parameters and Return Values
Functions are most useful when they can accept input and provide output.
Function Parameters (Input)
Parameters are variables listed inside the function definition parentheses. They act as placeholders for values passed when the function is called (arguments).
php
"; greetUser("Maria"); ?>Default Parameter Values
You can set a default value for a parameter. If the caller omits the argument, the default value is used.
php
"; } calculateTax(100); // Uses default rate (0.10) -> 110 calculateTax(100, 0.05); // Uses specified rate (0.05) -> 105 ?>Function Return Values (Output)
The return statement immediately stops function execution and sends a value back to the caller. Unlike echo, return doesn't output to the browser; it provides data for processing.
php