Functions
In PHP, a function is a piece of code which takes one or more inputs in the form of parameters and does some processing then returns a value. You already have seen many functions like echo()
, print_r()
, var_dump()
, etc. These are built-in functions, but PHP also allows you to create your own functions.
Defining a Function
A function is defined using the function
keyword, followed by a name and parentheses ()
:
Function Parameters
Information can be passed to functions through parameters:
Function Return Value
A function can return a value using the return
statement:
Functions are a way of encapsulating functionality that you wish to reuse. It makes your code more modular and easier to understand.
Last updated