Functions in PHP
Create reusable blocks of code using PHP functions with parameters and return values.
Andrew Turner
December 21, 2025
0.0k0
Functions let you reuse code instead of repeating it. ## Simple function ```php function greet() { echo "Hello!"; } greet(); ``` ## With parameters ```php function greetUser($name) { return "Hello $name"; } echo greetUser("Daniel"); ``` ## Default values ```php function greetUser($name = "Guest") { return "Hello $name"; } ``` ## Type hints (modern PHP) ```php function add(int $a, int $b): int { return $a + $b; } ``` > Next: Variable scope and global variables.
#PHP#Functions#Beginner