-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitems.php
38 lines (35 loc) · 835 Bytes
/
items.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
<?php
$I = [
"Vegetables"=> [
"0"=> "Asparagus",
"1"=> "Celery",
"Potatoes"=> ["Yukon gold potato", "Laura potato", "Red gold potato"]
],
"Fruits"=> [
"0"=> "Grapefruit",
"1"=> "Pineapple",
"Grapes"=> ["Red Grape", "Purple Grapes", "Green Grape"],
"2"=> "Avocado",
"3"=> "Bananas"
],
"Sweets"=> [
"Cakes"=> ["Napoleon", "Symphony"],
"Candies"=> [
"Lollipops"=> ["Chupa Chups", "Chupa Chups Mini"],
"0"=> "Haribo",
"1"=> "Gummi bears"
]
]
];
$pre = '';
tree($I, $pre);
function tree($I, $pre) {
$pre = $pre.'-';
foreach ($I as $k => $v) {
if (is_array($v)) {
echo "<br>{$pre}{$k}";
tree($v, $pre);
} else echo"<br>{$pre}{$v}";
}
}
?>