-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.php
45 lines (36 loc) · 1.26 KB
/
json.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
<?php
public function convertTest() {
$myArray = json_decode($this->sample_data);
echo $this->loopArray($myArray);
}
public function loopArray($myArray, $level = 0) {
$output = '';
foreach($myArray as $key => $value) {
if (!is_int($key)) {
$output .= '<br />' . $this->numberToDash($level). ' ' . $key;
}
if ((!is_object($value)) && (!is_array($value))) {
$output .= ' : ' . $value;
}
if ((is_object($value)) || (is_array($value))) {
$level++;
foreach ($value as $obj => $oVal) {
if (is_object($obj)) {
$output .= $this->loopArray($obj, $level);
} else if (is_array($obj)) {
$output .= $this->loopArray($oVal, $level);
} else {
$output .= $this->loopArray(array($obj => $oVal), $level);
}
}
}
}
return $output;
}
public function numberToDash($count) {
$dash = '';
for ($x = 0; $x < $count; $x++) {
$dash .= ' → ';
}
return $dash;
}