| PHP Functions |
| |
| Passing Parameters to a Functions |
| |
| Parameters (or arguments as they are more frequently known) can be passed into a function. There are no significant restrictions of the number of arguments which can be passed through to the function.
A function can be designed to accept parameters by placing the parameter names inside the parentheses of the function definition. |
| |
| Those variables can then be accessed from within the function body as follows: |
| |
<HTML>
<HEAD>
<TITLE>PHP Function: Passing Parameter
</TITLE></HEAD>
<BODY>
<?php
function sum ($val1, $val2)
{
$result=$val1+$val2;
echo $result;
}
?>
<hr>
<CENTER><H3>PHP Function: Passing Parameter</H3></CENTER>
<hr>
<p>Sum of 21 and 79 =<?php sum(21,79);?></p>
</BODY>
</HTML>
|
| |
| Type the above script and save it as function-parameter.php and open the page in the browser to view the output. |
| |
 |
| |
| In the above example the sum () function accepts two parameters as arguments, adds them together and returns the result. |
| |
| |
|
| |
| |