PHP Functions

PHP Functions can be seen as ‘block of code’ or ‘set of statements’ that perform some tasks when executed. A function usually takes some input arguments, perform some action on them and returns some result.

Example of a Simple PHP Function:

PHP Function With Arguments

You can pass some input arguments (also called parameters) into the functions. An argument is just like a variable on which you can perform some action.

Above function with take two arguments 10 & 25. Then, it perform addition operation on those numbers and returns total sum.

Function With Default Parameters Value

You can set a function with default parameter. When you can that function without passing that parameter, default parameter will be passed.

Function Returning Values

A function can return a value using the return statement. After ‘return’ the execution of the function stops and sends the return value back to the calling code.