-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22.3 Multidimensional Associative Array.php
More file actions
61 lines (54 loc) · 1.23 KB
/
22.3 Multidimensional Associative Array.php
File metadata and controls
61 lines (54 loc) · 1.23 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
<?php
// Multidimensional Associative Array
// Multidimensional arrays store multiple arrays whereas associative arrays store key-value pairs as data. Grouped relation between data can be stored in multidimensional associative arrays.
// Multidimensional Associative Array used
$marks = [
"dalveer" => [
"physics" => 85,
"maths" => 87,
"html" => 89
],
"dharmveer" => [
"physics" => 85,
"maths" => 77,
"html" => 59
]
];
echo "<pre>";
print_r($marks);
echo "</pre>";
// Multidimensional Associative Array use foreach Loop in program
$marks1 = [
"dalveer" => [
"physics" => 85,
"maths" => 87,
"html" => 89
],
"dharmveer" => [
"physics" => 85,
"maths" => 77,
"html" => 59
],
"dalveersingh" => [
"physics" => 85,
"maths" => 87,
"html" => 89
]
];
echo "<table border='2px' cellpadding='5px' cellspacing='0'
<tr>
<th> Student Name</th>
<th> Physics</th>
<th> Maths</th>
<th> Html</th>
</tr>
>";
foreach ($marks1 as $key => $v1) {
echo "<tr>
<td>$key</td>";
foreach ($v1 as $v2) {
echo "<td> $v2 </td>";
}
echo "</tr>";
}
echo "</table>";