PHP Programing language

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

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: