@ 2015-04-27T15:48:51Z <?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);*/
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Warning: foreach() argument must be of type array|object, int given in /in/Y0chR on line 90
Warning: Array to string conversion in /in/Y0chR on line 94
Warning: foreach() argument must be of type array|object, int given in /in/Y0chR on line 90
Warning: Array to string conversion in /in/Y0chR on line 94
Array
(
[2] => Tiger 1>>Array
[5] => Pferd 2>>Array
)
Output for 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.38 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.31 , 7.4.0 - 7.4.33 Warning: Invalid argument supplied for foreach() in /in/Y0chR on line 90
Notice: Array to string conversion in /in/Y0chR on line 94
Warning: Invalid argument supplied for foreach() in /in/Y0chR on line 90
Notice: Array to string conversion in /in/Y0chR on line 94
Array
(
[2] => Tiger 1>>Array
[5] => Pferd 2>>Array
)
Output for 4.3.0 - 4.3.10 , 4.4.0 - 4.4.9 , 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 7.3.32 - 7.3.33 Warning: Invalid argument supplied for foreach() in /in/Y0chR on line 90
Warning: Invalid argument supplied for foreach() in /in/Y0chR on line 90
Array
(
[2] => Tiger 1>>Array
[5] => Pferd 2>>Array
)
Output for 4.3.11 Array
(
[2] => Tiger 1>>Array
[5] => Pferd 2>>Array
)
preferences:dark mode live preview
263.2 ms | 401 KiB | 451 Q