-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
77 lines (61 loc) · 1.65 KB
/
index.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
<?php
$categories = [
[
'id' => 1,
'name' => 'Men',
'slug' => 'men',
'children' => [
[
'id' => 4,
'name' => 'Shirts',
'slug' => 'shirts',
'children' => [
[
'id' => 7,
'name' => 'Plain shirts',
'slug' => 'plain-shirts'
],
[
'id' => 8,
'name' => 'Denim shirts',
'slug' => 'denim-shirts'
]
]
],
[
'id' => 5,
'name' => 'Shoes',
'slug' => 'shoes'
],
[
'id' => 6,
'name' => 'Bags',
'slug' => 'bags'
]
]
],
[
'id' => 2,
'name' => 'Women',
'slug' => 'women',
],
[
'id' => 3,
'name' => 'Kids',
'slug' => 'kids'
]
];
$final_category_ids = [];
function recursion_get_all_category_ids($sub_categories,$final_category_ids){
foreach ($sub_categories as $key => $item) {
array_push($final_category_ids,$item['slug']);
if(!empty($item['children'])){
$final_category_ids = recursion_get_all_category_ids($item['children'],$final_category_ids);
}
}
return $final_category_ids;
}
$final_return_array = recursion_get_all_category_ids($categories[0]['children'],$final_category_ids);
echo '<br><br>';
echo 'final return array';
print_r($final_return_array);