<?php
/*$menu = array(
array(1,3,'Wurm 1.1', 2, 10),
array(2,6,'Vogel 2.1', 2, 30),
array(3,0,'Tiger 1', 1, 10),
array(4,6,'Hund 2.2', 2, 40),
array(5,3,'Katze 1.2', 2, 11),
array(6,0,'Pferd 2', 1, 20),
array(7,1,'Baer 1.1.1', 3, 0),
array(8,3,'Schwein 1.3', 2, 12),
array(9,4,'Esel 2.2.1', 3, 0),
);
// Algorithmus hier
$result = array();
var_dump($result == $target); */
$items = array(
array(
'mid' => 1, // Menuid
'pid' => 3, // parentid
'title' => 'Wurm 1.1', // title
'level' => 2, // level
'sid' => 10 // sortid
),
array(
'mid' => 2, // Menuid
'pid' => 6, // parentid
'title' => 'Vogel 2.1', // title
'level' => 2, // level
'sid' => 30 // sortid
),
array(
'mid' => 3, // Menuid
'pid' => 0, // parentid
'title' => 'Tiger 1', // title
'level' => 1, // level
'sid' => 10 // sortid
),
array(
'mid' => 4, // Menuid
'pid' => 6, // parentid
'title' => 'Hund 2.2', // title
'level' => 2, // level
'sid' => 40 // sortid
),
array(
'mid' => 5, // Menuid
'pid' => 3, // parentid
'title' => 'Katze 1.2', // title
'level' => 2, // level
'sid' => 11 // sortid
),
array(
'mid' => 6, // Menuid
'pid' => 0, // parentid
'title' => 'Pferd 2', // title
'level' => 1, // level
'sid' => 20 // sortid
),
array(
'mid' => 7, // Menuid
'pid' => 1, // parentid
'title' => 'Baer 1.1.1', // title
'level' => 3, // level
'sid' => 0 // sortid
),
array(
'mid' => 8, // Menuid
'pid' => 3, // parentid
'title' => 'Schwein 1.3', // title
'level' => 2, // level
'sid' => 12 // sortid
),
array(
'mid' => 9, // Menuid
'pid' => 4, // parentid
'title' => 'Esel 2.2.1', // title
'level' => 3, // level
'sid' => 0 // sortid
)
);
function listItems($array, $pid=0, $level=1) {
$result=array();
foreach ($array as $key => $item) {
if (($item['pid'] == $pid)
&& ($item['level'] == $level))
{
$result[$key] = $item['title'] . '>>' . listItems($item['mid'], ($level+1));
}
}
return $result;
}
print_r(listItems($items));
/*
foreach($items as $item){
}
function array_msort($array, $cols)
{
$colarr = array();
foreach ($cols as $col => $order) {
$colarr[$col] = array();
foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); }
}
$eval = 'array_multisort(';
foreach ($cols as $col => $order) {
$eval .= '$colarr[\''.$col.'\'],'.$order.',';
}
$eval = substr($eval,0,-1).');';
eval($eval);
$ret = array();
foreach ($colarr as $col => $arr) {
foreach ($arr as $k => $v) {
$k = substr($k,1);
if (!isset($ret[$k])) $ret[$k] = $array[$k];
$ret[$k][$col] = $array[$k][$col];
}
}
return $ret;
}
function listItems($items, $level=0, $child=false, $pid=0) {
array_msort($items, array(4 => SORT_DESC));
$rest = '';
foreach($items as $item) {
if ($item[3] != $level) {
continue;
}
if ($child == false) {
$rest .= '<li>'. $item[2] .'<ul>'. listItems($items, $level+1, true, $item[0]) .'</ul></li>';
} else {
if ($pid == $item[1]) {
$rest .= '<li>'. $item[2] .'<ul>'. listItems($items, $level+1, true, $item[0]) .'</ul></li>';
}
}
}
return '<ul>' . $rest . '</ul>';
}
echo listItems($navitems);*/
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename: /in/Y0chR
function name: (null)
number of ops: 8
compiled vars: !0 = $items
line #* E I O op fetch ext return operands
-------------------------------------------------------------------------------------
21 0 E > ASSIGN !0, <array>
101 1 INIT_FCALL 'print_r'
2 INIT_FCALL 'listitems'
3 SEND_VAR !0
4 DO_FCALL 0 $2
5 SEND_VAR $2
6 DO_ICALL
155 7 > RETURN 1
Function listitems:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 27
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 27
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 26
Branch analysis from position: 13
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename: /in/Y0chR
function name: listItems
number of ops: 30
compiled vars: !0 = $array, !1 = $pid, !2 = $level, !3 = $result, !4 = $item, !5 = $key
line #* E I O op fetch ext return operands
-------------------------------------------------------------------------------------
87 0 E > RECV !0
1 RECV_INIT !1 0
2 RECV_INIT !2 1
88 3 ASSIGN !3, <array>
90 4 > FE_RESET_R $7 !0, ->27
5 > > FE_FETCH_R ~8 $7, !4, ->27
6 > ASSIGN !5, ~8
91 7 FETCH_DIM_R ~10 !4, 'pid'
8 IS_EQUAL ~11 !1, ~10
9 > JMPZ_EX ~11 ~11, ->13
92 10 > FETCH_DIM_R ~12 !4, 'level'
11 IS_EQUAL ~13 !2, ~12
12 BOOL ~11 ~13
13 > > JMPZ ~11, ->26
94 14 > FETCH_DIM_R ~15 !4, 'title'
15 CONCAT ~16 ~15, '%3E%3E'
16 INIT_FCALL_BY_NAME 'listItems'
17 CHECK_FUNC_ARG
18 FETCH_DIM_FUNC_ARG $17 !4, 'mid'
19 SEND_FUNC_ARG $17
20 ADD ~18 !2, 1
21 SEND_VAL_EX ~18
22 DO_FCALL 0 $19
23 CONCAT ~20 ~16, $19
24 ASSIGN_DIM !3, !5
25 OP_DATA ~20
90 26 > > JMP ->5
27 > FE_FREE $7
98 28 > RETURN !3
99 29* > RETURN null
End of function listitems
Generated using Vulcan Logic Dumper, using php 8.0.0
preferences:
147.81 ms | 1403 KiB | 16 Q