Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
$struct = array();
$level = 0;
$helper =& $struct;
foreach($data as $item) {
if($level < $item['level']) {
$keys = array_keys($helper);
$helper =& $helper[$keys[count($keys)-1]]['children'];
} else if($level > $item['level']) {
$helper =& $struct;
for($i=0; $i<$level-1; $i++) {
$keys = array_keys($helper);
$helper =& $helper[$keys[count($keys)-1]]['children'];
}
}
$helper[$item['id']] = array(
'id' => $item['id'],
'name' => $item['name'],
'children' => array(),
);
$level = $item['level'];
}
Array
(
[0] => Array
(
[id] => 1
[name] => Root
[level] => 0
[children] => 7
)
[1] => Array
(
[id] => 3
[name] => Menschen
[level] => 1
[children] => 2
)
[2] => Array
(
[id] => 6
[name] => Afrikaner
[level] => 2
[children] => 1
)
[3] => Array
(
[id] => 14
[name] => Ureinwohner
[level] => 3
[children] => 0
)
[4] => Array
(
[id] => 9
[name] => Pflanzen
[level] => 1
[children] => 0
)
[5] => Array
(
[id] => 10
[name] => Steine
[level] => 1
[children] => 0
)
)
Array
(
[1] => Array
(
[id] => 1
[name] => Root
[type] => root
[level] => 0
[children] => Array
(
[3] => Array
(
[id] => 3
[name] => Menschen
[type] => content
[level] => 1
[children] => Array
(
[6] => Array
(
[id] => 6
[name] => Afrikaner
[type] => content
[level] => 2
[children] => Array
(
[14] => Array
(
[id] => 14
[name] => Ureinwohner
[type] => user
[level] => 3
[children] => Array
(
)
)
)
)
[9] => Array
(
[id] => 9
[name] => Pflanzen
[type] => content
[level] => 1
[children] => Array
(
)
)
[10] => Array
(
[id] => 10
[name] => Steine
[type] => content
[level] => 1
[children] => Array
(
)
)
)
)
)
)
)
Root
|
`-- Menschen
| |
| `-- Afrikaner
| |
| `-- Ureinwohner
|
`-- Pflanzen
|
`-- Steine
for($i=0; $i<$level-1; $i++) {
$keys = array_keys($helper);
$helper =& $helper[$keys[count($keys)-1]]['children'];
}
$i=0;
while($i<$item['level']) {
$keys = array_keys($helper);
$helper =& $helper[$keys[count($keys)-1]]['children'];
$i++
}