Functions that return true or false : Return Value « Functions « PHP






Functions that return true or false

 
<?
function can_pay_cash($cash_on_hand, $amount) {
    if ($amount > $cash_on_hand) {
        return false;
    } else {
        return true;
    }
}
function myFunction($meal, $tax, $tip) {
    $tax_amount  = $meal * ($tax / 100);
    $tip_amount  = $meal * ($tip / 100);
    $total_notip = $meal + $tax_amount;
    $total_tip   = $meal + $tax_amount + $tip_amount;

    return array($total_notip, $total_tip);
}

$total = myFunction(15.22,8.25,15);
if (can_pay_cash(20, $total)) {
    print "I can pay in cash.";
} else {
    print "Time for the credit card.";
}
?>
  
  








Related examples in the same category

1.Function return more than one value
2.Math Function Library
3.A Function That Returns a Value
4.Function Requiring Two Arguments
5.A Function That Returns a Value
6.Returning a value from a function
7.Returning an array from a function
8.Returning a list an array from function
9.Returning Values by Reference
10.Returning a Value by Reference
11.Returning by Reference
12.Returning More Than One Value
13.Multiple return statements in a function
14.return multiple values from a function
15.Using an array returned from a function
16.Passing Arguments and Returning Values by Reference
17.User-Defined Function to Determine a Leap Year