The function is used to return the value of the statement.
Example
[php]<?php
function sum($x, $y) {
$z = $x + $y;
return $z;
}
echo "5 + 10 = " . sum(5, 10) . "<br>";
echo "7 + 13 = " . sum(7, 13) . "<br>";
echo "2 + 4 = " . sum(2, 4);
?>[/php]
In the above function statement, first, we have to add the two variables $x
and $y
and return the sum in the return value $z
. We will be using the return value in the echo statement.
In the echo statement, we are asking php script to sum the values and return the variable $z
.
The above statement will generate the following result.
5 + 10 = 15
7 + 13 = 20
2 + 4 = 6