Functions and Scope
Return Values
A function can compute a value and return it to the caller.
Return Values
return_values.php
<?php
function subtotal(int $price, int $quantity): int {
$total = $price * $quantity;
return $total;
}
$quantity = ;
$amount = subtotal(7, $quantity);
echo "quantity=" . $quantity . "\n";
echo "amount=" . $amount . "\n";
<?php
function subtotal(int $price, int $quantity): int {
$total = $price * $quantity;
return $total;
}
$quantity = ;
$amount = subtotal(7, $quantity);
echo "quantity=" . $quantity . "\n";
echo "amount=" . $amount . "\n";
<?php
function subtotal(int $price, int $quantity): int {
$total = $price * $quantity;
return $total;
}
$quantity = ;
$amount = subtotal(7, $quantity);
echo "quantity=" . $quantity . "\n";
echo "amount=" . $amount . "\n";
return
`return` sends a value back to the expression that called the function.