-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortiranjeElemenata.php
116 lines (82 loc) · 2.39 KB
/
sortiranjeElemenata.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<?php
$brojevi = [15, -5, 10];
asort($brojevi);
foreach($brojevi as $s) {
echo $s . "<br>";
}
echo "<br>";
$brojevi = [1, 2, 3];
rsort($brojevi);
foreach($brojevi as $s) {
echo $s . "<br>";
}
echo "<br>";
$brojevi = ["Milos" => 1, "Dragan" => 5,"Vasilije" => 10];
asort($brojevi);
foreach($brojevi as $s) {
echo $s . "<br>";
}
echo "<br>";
$brojevi = ["Milos" => 4, "Dragan" => 5,"Vasilije" => 12];
ksort($brojevi);
foreach($brojevi as $s) {
echo $s . "<br>";
}
echo "<br>";
$brojevi = ["Milos" => 4, "Dragan" => 5,"Vasilije" => 12];
arsort($brojevi);
foreach($brojevi as $s) {
echo $s . "<br>";
}
echo "<br>";
$brojevi = ["Milos" => 4, "Dragan" => 5,"Vasilije" => 12];
krsort($brojevi);
foreach($brojevi as $s) {
echo $s . "<br>";
}
echo "<br>";
/*
Napraviti asocijativni niz boja gde ce kljuc biti heksadecimalna vrednost boje, a vrednost odgovarajuci naziv boje.
Na primer za crvenu boju kljuc ce biti #FF0000 a vrednost ce biti red.
Ovako zadat niz sortirati:
-rastuce u odnosu na hexadecimalni kod
-opadajuce u odnosu na hexdec kod
-rastuce u odnosu na naziv
-opadajuce u odnosu na naziv
*/
$niz = ["red" => "FF0000", "green" => "00FF00", "blue" => "0000FF"];
asort($niz);
foreach($niz as $boja => $boja_value) {
echo $boja_value . "<br>";
}
echo "<br>";
$niz = ["red" => "FF0000", "green" => "00FF00", "blue" => "0000FF"];
rsort($niz);
foreach($niz as $boja => $boja_value) {
echo $boja_value . "<br>";
}
echo "<br>";
$niz = ["red" => "FF0000", "green" => "00FF00", "blue" => "0000FF"];
ksort($niz);
foreach($niz as $boja => $boja_value) {
echo $boja_value . "<br>";
}
echo "<br>";
$niz = ["red" => "FF0000", "green" => "00FF00", "blue" => "0000FF"];
krsort($niz);
foreach($niz as $boja => $boja_value) {
echo $boja_value . "<br>";
}
echo "<br>";
?>
</body>
</html>