PHP Parametrized Function - php example - Phptpoint.com

PHP Parametrized Function

/ins>

Parametrized function in PHP

Parametrized function are used at run time of the program when output depends on dynamic values given at run time

There are two ways to access the parametrized function:

call by value : (here we pass the value directly )
call by reference : (here we pass the address location where the value is stored)

The following example will write different first names, but equal last name

Output
My name is Durgesh Pandey
My sister’s name is Poonam pandey
My brother’s name is Monu Pandey

in the above example1
There is a parametrized function named writeName()
that contains 1 parameter . In the first line we have printed a string message.and in the second line we have called the function along with the parameter value.

The given example add( ) and sub( ) has two parameters so pass two argument when call add( ) function
and sub( )function.

Output
Sum=3000
Sub=1000

in the example2
there are two parametrized function namely add() and sub() both containing two parameters.
at the time of calling these function , we have passed both these arguments.

Create dynamic add( ) and sub( ) function
Output
Enter second number

in example 3
there are two parametrized function namely add() and sub() both containing two parameters.
at the time of calling these function , we have passed both these arguments by using HTML form.
there are 2 buttons add and sub .the output of the program is based upon the clicking of button by the user at run time. i.e if user click on add button the add function get called.

Function Return type

To let a function return a value, use the return statement.

Output
84 + 16 = 100
Make your own library and call it on another pages.

Download library