Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //исходные данные
- $fruits = array();
- $fruits[] = array(
- 'name' => 'Бананы',
- 'price' => 65,
- );
- $fruits[] = array(
- 'name' => 'Ананасы',
- 'price' => 90,
- );
- $fruits[] = array(
- 'name' => 'Яблоки',
- 'price' => 50,
- );
- $fruits[] = array(
- 'name' => 'Груши',
- 'price' => 80,
- );
- $fruits[] = array(
- 'name' => 'Кокосы',
- 'price' => 130,
- );
- class Fruiting {
- public $fruits;
- public $weights;
- public function setData($fruits, $weights) {
- $this->fruits = $fruits;
- $this->weights = $weights;
- }
- private function getPrice($price, $weight) {
- $result_price = $price * $weight;
- return $result_price;
- }
- public function getResult() {
- //перебираем все фрукты
- foreach ($this->fruits as $fruit) {
- //перебираем все веса для каждого фрукта
- foreach ($this->weights as $weight) {
- echo $fruit['name'] . ' ' . $weight . 'кг стоят ' . self::getPrice($fruit['price'], $weight) . 'руб.<br />';
- }
- }
- }
- }
- $fruiting = new Fruiting();
- $fruiting->setData($fruits, array(5, 12, 14, 16, 22, 135, 150, 200, 254, 300, 400));
- $fruiting->getResult();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment