What is a PHP function?
Answer
A function in PHP is a reusable block of code that performs a specific task. Define with the function keyword: function greet(string $name): string { return "Hello, $name!"; }. PHP functions support default parameter values, type declarations (PHP 7+), and return type declarations. PHP passes arguments by value by default — to pass by reference, prefix the parameter with &: function increment(int &$n): void { $n++; }. PHP also has variable functions (storing a function name in a variable and calling it), anonymous functions (closures), and arrow functions (PHP 7.4+). Functions are globally scoped by default in PHP.
Previous
What is the difference between include and require in PHP?
Next
What is the difference between null, false, and empty string in PHP?