-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.php
More file actions
95 lines (77 loc) · 1.91 KB
/
Array.php
File metadata and controls
95 lines (77 loc) · 1.91 KB
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
<?php
// $numbers = [1, 2, 2, 3, 4, 4, 5];
// $unique = [];
// for ($i = 0; $i < count($numbers); $i++) {
// $isDuplicate = false;
// for ($j = 0; $j < count($unique); $j++) {
// if ($numbers[$i] == $unique[$j]) {
// $isDuplicate = true;
// break;
// }
// }
// if (!$isDuplicate) {
// $unique[] = $numbers[$i];
// }
// }
// print_r($unique);
$foods = [
'vegetables'=>'carrot', 'capsicam', 'brinjal', 'brocolli',
'fruits'=>'orange', 'banana', 'apple',
'drinks'=>'water', 'milk',
];
$data = ['carrot', 'capsicam', 'brinjal', 'brocolli'];
// echo $data[1];
$data[] = "Onion"; //Add Data in Array
// print_r($data);
$employees = [
"Manager" => "Alice",
"Developer" => "Bob"
];
// echo $employees["Manager"];
// print_r($employees);
// foreach($employees as $key=>$item){
// echo $key. " : ".$item.PHP_EOL;
// }
$students = [
[
"Name" => "Sakib",
"Grade" => "A",
"Scores" => [90, 85]
],
[
"Name" => "Rakib",
"Grade" => "A+",
"Scores" => [94, 99]
]
];
// echo $students[0]["Name"];
// foreach($students as $item){
// echo $item["Name"]." ". $item["Grade"].PHP_EOL;
// }
$prices = [100, 400, 230];
$prices_with_vat = array_map(function ($item) {
return $item*1.10;
}, $prices);
// print_r($prices_with_vat);
/**Array Reduce Next Part next day*/
$score = [20, 34, 100, 23, 13, 89];
$filter_with_score = array_filter($score, function ($item) {
return $item >= 89;
});
// print_r($filter_with_score);
$monthlySales = [15000, 20000, 12000, 22000];
$totalSale = array_reduce($monthlySales, function ($carry, $item) {
return $carry + $item;
}, 0);
// echo "Total Sales: ". $totalSale . " Taka\n";
$cities = [
"Dhaka" => 18,
"Chittagong" => 7,
"Rajshahi" => 5,
"Bogura" => 14,
"Bhola" => 9
];
asort($cities);
print_r($cities);
ksort($cities);
print_r($cities);