Sometimes you may want to call a function and have a value returned back to the main coding area. This is done using the return command.
Example :
Result :
Leaving the return command out, the result would be blank.
In the above example, the variable $total calls the function entering two arguments. The function takes the numbers and finds the sum. The sum value is "returned" back to the calling variable $total.
Example :
<?php
function addit($first_number,$second_number){
$total_sum = $first_number + $second_number;
return $total_sum;
}
$first_number = "1";
$second_number ="2";
$total = addit($first_number,$second_number);
echo "$total";
?>
function addit($first_number,$second_number){
$total_sum = $first_number + $second_number;
return $total_sum;
}
$first_number = "1";
$second_number ="2";
$total = addit($first_number,$second_number);
echo "$total";
?>
Result :
3
Leaving the return command out, the result would be blank.
In the above example, the variable $total calls the function entering two arguments. The function takes the numbers and finds the sum. The sum value is "returned" back to the calling variable $total.

