Introduction
PHP is composed of a set of one or more functions. Functions divide large programs into smaller, easier to handle pieces. Each function normally performs one specific task. Functions are used to reduce the code in the programming i.e. reusability. Functions can be placed anywhere in a page. PHP has more than 700 built-in functions.
Types of PHP Functions
In this article I will describe only three types of functions, which are as follows:
- Simple Functions
- Functions with Parameter
- Functions with Return values
Simple Functions
A Simple function does not take any arguments (parameters) or values. The function name should start with a letter or underscore (_), but not a number.
Syntax
function functionName()
{
message ;
}
Example
- <?php
- function CompnyName()
- {
- echo "MCN Solutions Pvt. Ltd. Noida.";
- }
- echo "My company name is ";
- CompnyName();
- ?>
In the above example we build a CompnyName() function and print a message inside this function. This function is called later for printing the message.
PHP Functions with Parameter
We can add arguments (parameters) to a function. Using parameters, we can add more functionally to a function. An argument is just like a variable of PHP. An argument (parameter) is specified inside the parenthesis of a function.
Syntax
function functionName (argument1,argument2)
{
message ;
}
Example 1
- <?php
- function CompnyName ($fullname) // one argument i.e. $fullname
- {
- echo $fullname;
- }
- echo "My company name is ";
- CompnyName ("MCN Solutions Pvt. Ltd. Noida.");
- ?>
In the above example we build a CompnyName() function and an argument as a $fullname. This argument shows the message when you write a message in this function.
Example 2

Asfend YarPosted Feb 29, 2016, 10:58 AM
nice
Santhakumar MunuswamyPosted Aug 22, 2015, 7:16 AM
Good Article. Thanks for sharing
Sandeep KumarPosted Aug 21, 2015, 8:01 AM
thank you van lai :)
Sandeep KumarPosted Aug 21, 2015, 8:01 AM
thank you Gopi chand sir :)
Sandeep KumarPosted Aug 21, 2015, 8:00 AM
thank you Gowtham K sir :)
Sandeep KumarPosted Aug 21, 2015, 7:58 AM
thank you pankaj sir :)
Van LaiPosted Aug 20, 2015, 9:22 PM
I'm learning PHP from scratch. Thank you for sharing.
Gopi ChandPosted Aug 20, 2015, 1:42 PM
Its nice one
Gowtham KPosted Aug 20, 2015, 12:42 PM
Good one thanks for sharing
Pankaj Kumar ChoudharyPosted Aug 20, 2015, 12:16 PM
Nice Article Sandeep...............
Sandeep KumarPosted Aug 20, 2015, 11:15 AM
Thank you sir :)
Rahul PrajapatPosted Aug 20, 2015, 10:02 AM
Very helpfull article Sandeep Kumar sir