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,
- );
- //вернёт стоимость
- function getPrice($price, $weight) {
- $result_price = $price * $weight;
- return $result_price;
- }
- //вернёт все веса
- function getWeights() {
- return array(5, 12, 14, 16, 22, 135, 150, 200, 254, 300, 400);
- }
- //получаем веса в переменную
- $weights = getWeights();
- //перебираем все фрукты
- foreach ($fruits as $fruit) {
- //перебираем все веса для каждого фрукта
- foreach ($weights as $weight) {
- echo $fruit['name'] . ' ' . $weight . 'кг стоят ' . getPrice($fruit['price'], $weight) . 'руб.<br />';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment