PHP Parameterized Function

Those function which accept parameter are called parameterized functions. You can pass more than one parameter to a function. Passed parameters are represented inside the parenthesis after the function name.

On passing dynamic parameter, you can reuse as per your different requirements. The values passed in parameterized functions are called arguments.


Let’s understand with the help of an example-

1. Addition program using parameterized function.

function addition($val1, $val2)
{
   $sum = $val1 + $val2;
   echo "Addition of $val1 and $val2 is ". $sum;
}

//calling the addition function
addition(10,50);

//result
Sum of 10 and 50 is 60

2. Subtraction program using parameterized function.

function subtraction($val1, $val2)
{
   $sub= $val1 - $val2;
   echo "Subtraction of $val1 and $val2 is ". $sub;
}

//calling the subtraction function
subtraction(80,50);

//result
Subtraction of 80 and 50 is 30

Trending Topics