PHP User Define function

Passing Functions Arguments in PHP

In PHP you can also pass the argument to the function . These argument are the may be variables or constants values. Function can be handed variables, so that you can pass the variable over to your functions by typing them inside of the round brackets of the function name and also you can directly pass the value to the function. when we pass variable we say " Passing Arguments by Reference ". If we pass value as argument the we say "passing Argument by Value".
Following example pass an integer value to Function.


<?php
function display($x)
{
echo "This is your passed value=" . $x;

}
 echo "This code is written out side the function below code call the function" . "<br />";

display(200);

?>
 
 

This will display following result:
This code is written out side the function below code call the function
This is your passed value=200

PHP Functions returning value

A function can also return the value to calling function . The function may be return one or more then value in form of array.
For example:
We takes two integer parameters and add them together and then returns their sum to the calling program.


<?php
function addvalue($num1, $num2)
{
$sum = $num1 + $num2;
return $sum;
}
$sum = addvalue(10, 20);
echo "Sum of two number is =" .  $sum" ;
?>

Default Values for Function Parameters

The default value of function parameters is, if we declare a function which get some argument but if we not pass any parameter then this default value us used as parameters.


<?php
function display($name = "Leraninghints")
{
echo  $name;
}
display();

?>

In above code the function, display call with out any argument . but in Out put this function display the "Learninghints".