What is PHP Function?

A function is a block of statements that does one specific job. It can take values as input (parameters), do some work and give back a result. You write it once and call it whenever you need.

<?php
function add($a, $b) {
    return $a + $b;
}

echo add(5, 3);
?>

Output:

Tutorials Class - Output Window

8

PHP has many built-in functions (like strlen()) and you can also create your own with the function keyword. Learn more in PHP Functions.


Learn more about the similar topics:
Tutorials
PHP Functions
Exercises & Assignments
Factorial program in PHP using recursive function
Write a PHP program to check if a person is eligible to vote
Write a PHP program to calculate area of rectangle
Interview Questions & Answers
What is PHP Function?
What is PHP floor() function?