0

I have a home work from the PHP class, and the teacher ask me to calculate the revenue for the retailer based on the product they sold and country of the buyer. Below are the products and the country, let's call them as Tier:

ProductTier = Apple, Orange, Banana, Watermelon, Grape, Pear

CountryTier:
    CountryTier1 = US, CA
    CountryTier2 = FR, UK
    CountryTier3 = JP, SG

RevenueTier:
    RevenueTier1 = 2, 4 ,6, 8, 10, 12
    RevenueTier2 = 1, 3, 5, 7, 9, 11
    RevenueTier3 = 1, 1, 1, 1, 1, 1

With that table, what i have to do is get the buyer country, check what they bought and print revenue for the retailer. I have wrote a small function to check the buyer country and then return their CountryTier, but i don't know what to do next. Assuming that there are a buyer come from the UK and they bought the Orange so the retailer will have $3 for the revenue, do you have any suggestion for me to do this exercise with less of code.

ps: Please correct/ask me if something not clearly.

4

1 回答 1

0

存储您的收入,例如:

$revenue = array();
$revenue[1] =  array(2, 4 ,6, 8, 10, 12);
$revenue[2] =  array(1, 3, 5, 7, 9, 11);
$revenue[3] =  array(1, 1, 1, 1, 1, 1);

将 ProductTiers 存储为

$productTiers = array('Apple', 'Orange', 'Banana', 'Watermelon', 'Grape', 'Pear');

现在使用获取 ProductTier 的密钥

$key = array_search($fruitName, $productTiers);

现在您可以使用

$revenue[$countryTier][$key];
于 2014-02-16T13:18:08.197 回答