-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.php
More file actions
144 lines (137 loc) · 3.01 KB
/
list.php
File metadata and controls
144 lines (137 loc) · 3.01 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
// List array structure.
$list_items = [
'type' => 'ol',
'items' => [
[
'text' => 'India',
'child' => [
'type' => 'ol',
'items' => [
[
'text' => 'Maharashtra',
'child' => [
'type' => 'ul',
'items' => [
[
'text' => 'Pune',
],
[
'text' => 'Nashik',
],
],
],
],
[
'text' => 'Karnataka',
],
[
'text' => 'Rajasthan',
'child' => [
'type' => 'ul',
'items' => [
[
'text' => 'Pushkar',
],
],
],
],
]
]
],
[
'text' => 'US',
'child' => [
'type' => 'ul',
'items' => [
[
'text' => 'New York',
],
[
'text' => 'Kansas',
],
],
],
],
[
'text' => 'Pakistan',
'child' => [
'type' => 'ol',
'items' => [
[
'text' => 'Balochistan',
],
[
'text' => 'Punjab',
'child' => [
'type' => 'ul',
'items' => [
[
'text' => 'Lahore',
],
[
'text' => 'Faisalabad',
],
],
],
],
],
],
]
],
];
// Logic to output list items from $list_items.
/**
* Funtion to get list type.
*/
function get_list_type($arr) {
if (array_key_exists('type',$arr)){
return $arr['type'];
}
return NULL;
}
/**
* Funtion to get list items.
*/
function get_items($arr) {
if (array_key_exists('items',$arr)) {
return $arr['items'];
}
return NULL;
}
/**
* Funtion to get child items in the list.
*/
function get_list_child($arr) {
if (array_key_exists('child',$arr)){
return $arr['child'];
}
return NULL;
}
$list_type = get_list_type($list_items);
if ($list_type != NULL) {
echo "<".$list_type.">";
$countries = get_items($list_items);
for ($i = 0; $i < sizeof($countries); $i++){
echo "<li>".$countries[$i]['text']."</li>";
$country_child = get_list_child($countries[$i]);
$country_child_type = get_List_type($country_child);
echo "<".$country_child_type.">";
$states = get_items($country_child);
for($j=0;$j<sizeof($states);$j++){
echo "<li>".$states[$j]['text']."</li>";
$state_child = get_list_child($states[$j]);
if ($state_child != NULL){
$state_child_type = get_list_type($state_child);
echo "<".$state_child_type.">";
$cities = get_items($state_child);
for ($k =0; $k < sizeof($cities);$k ++){
echo "<li>".$cities[$k]['text']."</li>";
}
echo "</".$state_child_type.">";
}
}
echo "</".$country_child_type.">";
}
echo "</".$list_type.">";
}