PHP Functions – Passing Values
Posted by tutor | Posted in PHP Tutorial | Posted on 09-08-2010-05-2008
0
Communication between a function and a main program is through the parameters, which are actually the mode of passing information.
Parameters are the arguments that are passed to the functions to extend their usage.
A parameter is just like a variable which is passed to a function to perform some operations on those values.
Parameters are specified as comma separated variables just after the function name, inside the parentheses.
Single parameter function
<html>
<body>
<?php
function display($par1)
{
echo $par1.”<br />”;
}
$a=1;
$b=2;
$c=3;
$d=4;
display($a);
display($b);
display($c);
display($d);
?>
</body>
</html>
1
2
3
4
Multiple parameter function
<html>
<body>
<?php
function add($a,$b)
{
echo $a+$b.”<br />”;
}
$x=3;
$y=4;
add($x,$y);
?>
</body>
</html>
7
