Functions in PHP are blocks of code that can be reused. You define a function and then call it whenever you need it.
To define a function in PHP, use the function
keyword:
<?php
function greet($name) {
echo "Hello, $name!";
}
greet("John");
?>
Write a function that takes two numbers as parameters and returns their sum.
Answers: The function
keyword; Call a function by writing its name followed by parentheses (e.g., greet()
).