fork(1) download
  1. <?php
  2.  
  3. $buyList = array(
  4. array('name' => 'Телевизор', 'price' => '400', 'quantity' => 1),
  5. array('name' => 'Телефон', 'price' => '300', 'quantity' => 3),
  6. array('name' => 'Кросовки', 'price' => '150', 'quantity' => 2),
  7. );
  8.  
  9. function resultBuyList($buyList)
  10. {
  11.  
  12. $creditCount = 0;
  13. $productCount = 0;
  14. foreach ($buyList as $key => $value) {
  15. $credits = $value['quantity'] * $value['price'];
  16. $creditCount += $credits;
  17. $productCount += $value['quantity'];
  18. }
  19. return $result = "Вы купили $productCount единиц товара, общая сумма к оплате: $creditCount";
  20. }
  21.  
  22.  
  23. echo resultBuyList($buyList);
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
Вы купили 6 единиц товара, общая сумма к оплате: 1600