tristamoff

Untitled

Feb 3rd, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2. //исходные данные
  3. $fruits = array();
  4. $fruits[] = array(
  5.   'name' => 'Бананы',
  6.   'price' => 65,
  7. );
  8. $fruits[] = array(
  9.   'name' => 'Ананасы',
  10.   'price' => 90,
  11. );
  12. $fruits[] = array(
  13.   'name' => 'Яблоки',
  14.   'price' => 50,
  15. );
  16. $fruits[] = array(
  17.   'name' => 'Груши',
  18.   'price' => 80,
  19. );
  20. $fruits[] = array(
  21.   'name' => 'Кокосы',
  22.   'price' => 130,
  23. );
  24.  
  25. //вернёт стоимость
  26. function getPrice($price, $weight) {
  27.   $result_price = $price * $weight;
  28.   return $result_price;
  29. }
  30. //вернёт все веса
  31. function getWeights() {
  32.   return array(5, 12, 14, 16, 22, 135, 150, 200, 254, 300, 400);
  33. }
  34.  
  35. //получаем веса в переменную
  36. $weights = getWeights();
  37. //перебираем все фрукты
  38. foreach ($fruits as $fruit) {
  39.   //перебираем все веса для каждого фрукта
  40.   foreach ($weights as $weight) {
  41.     echo $fruit['name'] . ' ' . $weight . 'кг стоят ' . getPrice($fruit['price'], $weight) . 'руб.<br />';
  42.   }
  43. }
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment