Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
0
Indexable
Never
<!DOCTYPE html>
<html>
<head>
	<title>Задание 2</title>
</head>
<body>
<p>Найдите продукты с одинаковой ценой</p>
<?php

// ассоциативный массив продуктов и их цен
$food["Apple"] = 30;
$food["Banana"] = 130;
$food["Cherry"] = 30;
$food["Coconut"] = 130;
$food["Kiwi"]= 230;
$food["Pineapple"] = 90;
$food["Lime"] = 90;
$food["Lemon"] = 50;
$food["Mango"] = 130;
$food["Olive"] = 90;
$food["Peach"] = 50;
$food["Avocado"] = 230;
$food["Cucumber"] = 30;
$food["Carrot"] = 10;
$food["Tomato"] = 10;
$food["Cabbage"] = 20;
$food["Potatoes"] = 40;
$food["Pepper"] = 50;
$food["Turnip"] = 20;
$food["Haricot"] = 10;

$color[1] = "black";
$color[2] = "red";
$color[3] = "blue";
$color[4] = "green";
$color[5] = "yellow";
$color[6] = "brown";
$color[7] = "magenta";
$color[8] = "orange";

$arr = $food;
asort($arr);
$tmp = 0;
$k=1;
foreach ( $arr as $key => $value) {
	if ($tmp == $value) continue;
	else {
		$tmp = $value;
		$arr_k[$tmp] = $color[$k++];
	}
}

foreach ( $food as $key => $value) {
	echo "<font color=$arr_k[$value]>Продукт ".$key." стоит ".$value." рублей</font><br />";
}
?>
</body>
</html>