PHP: Returning a value from a function

This entry is part 33 of 54 in the series PHP Tutorial

To return value from functions, use the return keyword with a value to return.


function restaurant_check($meal, $tax, $tip) {
    $tax_amount = $meal * ($tax / 100);
    $tip_amount = $meal * ($tip / 100);
    $total_amount = $meal + $tax_amount + $tip_amount;

    return $total_amount;

$total = restaurant_check(25,7,15);

echo "Total spent is $total";

Series Navigation<< PHP: Built-in functions
PHP: Returning an array in a function >>

Leave a comment

Leave a Reply