PHP Functions

Thursday, December 10th, 2015 PHP, Programming

A PHP function is a block of statements that can be used repeatedly in a program. It is not executed when page is loaded, instead implemented when a function is called.

 

Function Syntax

Function function _name ()
{
Code to be executed;
}
 

Example

Function test()
{
Echo “hello”;
}
Test();
 

Function with arguments

Arguments or parameters are a piece of information, which is passed to function for executing the code. Functions can have any number of arguments, just separate them by comma.

 

Function test($fname)
{
Echo $fname;
}
Test(“janani”);

 

Default Argument Value

The default argument will be set, if a function is called without parameters.

 
Function test($fname=50)
{
Echo $fname;
}
Test();
 

Return value function

Return value function is used when a function has to return a value after code execution.

 
Function test ($a, $b)
{
Return $a+$b;
}
Echo Test(2,3);

No comments yet.

Leave a comment

Request a Free SEO Quote