The PHP return statement is used to tell a PHP function to send information back to the calling program. This can be useful in many ways. For example, you can use a function to calculate the sales tax for a shopping cart program. Let's use a factious online business for our example. This business has an online store and three brick and mortar storefronts in Indiana, Ohio and Maine. This means that sales tax must be calculated for online purchases by customers in these three states. We will use our function to do the calculation. When we call the function, we will need to pass it some information (called arguments). We will pass the total dollar amount of the customer's purchase ($purchases) and the percent sales tax ($sales_tax) for each transaction. We know which state the customer lives in because he gave us that information when he opened his customer account. The function will calculate the amount of sales tax for this purchase and pass that value back to the shopping cart program. Let's take a look at the code. For our example below the total dollar amount of the purchase is $100 and the percent sales tax is .05.
| ||||||