PHP functions are similar to
other programming languages. A function is a piece of code which takes one more
input in the form of parameter and does some processing and returns a value. Each
function has a unique name and set of statement to perform the specific task. Functions
declare in PHP with function keyword. Functions are useful because they contribute
to rapid, reliable, error-reducing coding and increase legibility by tiding up complicated
code sequences. They are two types in PHP.
1. Built in Functions
2.
User Define Functions
1. Built in Functions
We can use many functions in programming.
these Functions only use for available. We
cannot give definition for these Functions because this only define by PHP developer.
In the PHP Programming we always use these Function when we need to perform for
any special task. These Functions is already defined in PHP Library.
For Example:
Phpinfo(
), include( )
2. User Define Functions:
Use defines Functions created
by the programmer. These type of Functions user can give any name in PHP Programming.
We cannot use any space in the Functions name and after of Functions name we must
define brace “ ( )” which is symbol of Functions. A function will
not execute immediately when a page loads. A Function will be execute by a call to the function.
Here Video Provide
Syntax :
Function function-name( )
{
Body of function;
}
Example
<?php
Function helloo( )
{
echo “this is first program
in function ”;
}
helloo( );
?>
PHP Function with Arguments:
Information can be passed to Function
through arguments. An argument is just like variable. Argument are specified after
the function name and inside the parentheses.
Program :
<?php
function family($fname) //argument
{
echo “$fname refsnes.<br>”;
}
family(“smith”);
family(“john”);
family(“jeany”);
family(“aman”);
family(“raman”);
?>
PHP Function with return type
This is used to return the
type of data.
<?php
Function sum($x, $y)
{
$z= $+$y;
return $z;
}
echo “5 +10 =” .sum( 5,10).”<br/>”;
echo “15 +10 =” .sum( 15,10);
?>
Here Video Provide