PHP FUNCTION A function is a group of reusable code which can be called anywhere in the program. This eliminates the need of writing same code again and again. In other words, you can implement the concept of reusability through functions. Because, once you have defined a function block in your program, thereafter you can call it for number of times at any point in the program. Function will help programmers to write modular code. You can divide your big program into a number of small and manageable functions. This is called modularity. Like any other advance programming language, PHP also supports all the features required to write modular code using functions. PHP provides a number of built-in functions that you can use to enhance and empower your applications. At the same time, PHP allows you to write your own functions as well. 1. Creating User-defined Functions in PHP It is very easy to create your own PHP function. A user-defined function declaration starts with the keyword "function". Suppose you want to create a PHP function which will simply display a message “Good Morning” on your browser when you will call it. Following example creates a function called Message() and then calls it just after creating it: User-defined Function After the execution of above code, the output would be look like:

2. Functions with Arguments and Returning Values In PHP, information can be passed to functions through arguments. An argument is just like a variable. Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma. A PHP function can also return a value using the return statement. Example: Function with Arguments and Return Value

After the execution of above code, the output would be look like: