PHP Programing language

adplus-dvertising
Which type to Returning data from Functions
Previous Home Next
You have got a simple function name adder that returns the sum of the two numbers passed to it. You might start writing adder like this:
<?php
function adder(operand_1,operand_2)
{
	$sum = $operand_1 + $operand_2;
}
?>
Now you have got the sum in the variable named $sum, how do you return that value to the calling ode? you can use the PHP return statement:
<?php
function adder(operand_1,operand_2)
{
	$sum = $operand_1 + $operand_2;
	return $sum;
}
?>
Program:
<html>
<head>
<title>Returning values from Function  </title>
<body>
<h1>Returning values from Function </h1>
<?php
echo "Passing 'How' 'are' 'things?' to connector...<br>";
echo "Getting this result:";
connector ("How","are","things?");
function connector()
{
$data = "";
$arguments = func_get_args();
for ($loop_index=0; $loop_index <func_num_args();
$loop_index++)
{
$data .= $arguments [$loop_index]." ";
}
echo $data;
}
?>
</body>
</html>

Output:

Previous Home Next