-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray_sort.php
124 lines (102 loc) · 2.88 KB
/
array_sort.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
117
118
119
120
121
122
123
124
<?php
/*
sort() - sort arrays in ascending order
rsort() - sort arrays in descending order
asort() - sort associative arrays in ascending order, according to the value
ksort() - sort associative arrays in ascending order, according to the key
arsort() - sort associative arrays in descending order, according to the value
krsort() - sort associative arrays in descending order, according to the key
*/
$name=array("Ratan","Alal","Shaon","Faysol","Hasan");
rsort($name);
for($i=0;$i<count($name);$i++)
{
echo$name[$i]."<br />";
}
$Employee_name=array("Ratan"=>30,"Alal"=>23,"Shaon"=>32,"Faysol"=>25,"Hasan"=>26);
krsort($Employee_name);
foreach($Employee_name as $name=>$age)
{
echo"Name".$name." and Age: $age <br />";
}
$trainee=array(20,43,15,27,40,32,50,20,100,125,110);
$a=0;
foreach($trainee as $key=>$val)
{
if($val>$a)
{
$a=$val;
}
}
echo"The highest value is: $a<br/>";
echo"<br />";
//Write a PHP script to calculate and display average temperature, five lowest and highest temperatures.
$record=array(40,32,24,33,12,54,65,35,66,76);
$sum=0;
echo"Records Are:<br/>";
for($i=0;$i<count($record);$i++)
{
echo$record[$i].",";
$sum=$sum+$record[$i];
}
echo"<br/>";
echo"The sum of total records is:".$sum."<br/>";
$av=$sum/count($record);
echo"The average is:$av<br/>";
rsort($record);
echo"The Highest five records are:<br/>";
for($i=0;$i<5;$i++)
{
echo$record[$i].",";
}
echo"<br/>";
sort($record);
echo"The Lowest five records are:<br/>";
for($i=0;$i<5;$i++)
{
echo$record[$i].",";
}
//Write a PHP script to calculate and display average Marks, five lowest and highest Marks.
echo"<br/>";
$Marks=array(55,33,78,98,72,66,51,69,84,74);
$sum=0;
echo"Marks are: ";
for($i=0;$i<count($Marks);$i++)
{
echo$Marks[$i]." ";
$sum=$sum+$Marks[$i];
}
echo"<br />";
echo"Total Marks is: $sum <br />";
$avg=$sum/count($Marks);
echo"Average Mark is: $avg <br />";
echo"Five highest Marks are: <br />";
rsort($Marks);
for($i=0;$i<5;$i++)
{
echo$Marks[$i]." ";
}
echo"<br />";
echo"Five Lowest Marks are: <br />";
sort($Marks);
for($i=0;$i<5;$i++)
{
echo$Marks[$i]." ";
}
echo"Records Are:";
echo"<br />";
$records=array(40,32,24,33,12,54,65,35,66,76);
$rec=array_rand($records,10);
echo$records[$rec[0]]."<br />";
echo$records[$rec[1]]."<br />";
echo$records[$rec[2]]."<br />";
echo$records[$rec[3]]."<br />";
echo$records[$rec[4]]."<br />";
echo$records[$rec[5]]."<br />";
echo$records[$rec[6]]."<br />";
echo$records[$rec[7]]."<br />";
echo$records[$rec[8]]."<br />";
echo$records[$rec[9]];
$rr=array("akmal hossain"=>24,"alal"=>23);
echo"<br />".$rr['alal'];
?>