PHP User Defined Function

Here I like to explain php user defined function with an example.

Apart from built-in function, user can define his own function.In PHP user defined function is declared using function keyword.Below I will declare a function for addition of two numbers.

function Sum($a,$b)

{

$c= $a+$b;

return $c;

}

echo sum(5,3);

?>

The above example shows how to declare a user defined function.Function key word declare a function 

called Sum.That is sum is function with two arguments.It accepts two values, and add theses two values and return the result.We can call this any where in the program.So it reduces length of the code.

The “echo sum(5,3); line invoke the function and the function return the result value(here 5+3=8).

One Response

09.08.17

I’m afraid this is beyond me but I’m sure this is very useful information for others.

Leave Your Response