PHP Functions
Functions in PHP are blocks of code that can be reused. They allow you to encapsulate functionality and make your code more modular and maintainable.
Syntax
function functionName() {
// code to be executed
}
Example of PHP Function
<?php
function greet($name) {
return "Hello, " . $name . "!";
}
echo greet("World");
?>
Output:
Hello, World!
Explanation: This example demonstrates how to define and call a function in PHP. The function greet
takes a parameter $name
and returns a greeting message.