@ 2014-05-26T05:58:35Z <?php
function getTree($treeByParent, $treeByCat, $id, $lastId) {
$gTree = [];
if ($id != $lastId) {
$gTree[] = $id;
if ( isset($treeByCat[ $id ]) && count($treeByCat[ $id ]) > 0 ) $gTree = array_merge( getTree($treeByParent, $treeByCat, $treeByCat[ $id ], $id), $gTree);
if ( isset($treeByParent[ $id ]) && count($treeByParent[ $id ]) > 0 ) {
foreach ($treeByParent[ $id ] as $cat) {
$gTree = array_merge( getTree($treeByParent, $treeByCat, $cat, $id), $gTree);
}
}
return $gTree;
}
}
function display_parent_nodes($data, $id)
{
$tree = array(
"parents" => array();
"children" => array();
"full" => array();
);
$current = $data[$id];
$parent_id = $current === NULL ? "NULL" : $current;
$tree['parents'][] = $parent_id;
while (isset($data[$parent_id])) {
$current = $data[$parent_id];
$parent_id = $current === NULL ? "NULL" : $current;
$tree['parents'][] = $parent_id;
}
echo implode(" > ", array_reverse($tree['parents']));
global $data, $index;
$parent_id = $parent_id === NULL ? "NULL" : $parent_id;
if (isset($index[$parent_id])) {
foreach ($index[$parent_id] as $id) {
$children[] = $id;
$children = array_merge($children, get_child_nodes2($id));
}
}
foreach ($childIds as $child_id) {
$children = array_keys($data, $child)
while (isset($data[$children])) {
$current = $data[$children];
$child_id = $current === NULL ? "NULL" : $current;
$tree['children'][] = $child_id;
}
}
echo " > ". implode(" > ", $tree['children']);
}
$treeByParent = array(
0 => array(1, 2),
1 => array(3, 7),
3 => array(4),
4 => array(5),
5 => array(6, 8)
);
$treeByCat = array(
1 => 0,
2 => 0,
3 => 1,
7 => 1,
4 => 3,
5 => 4,
6 => 5,
8 => 5
);
print_r( display_parent_nodes($treeByCat, 4) );
//print_r( getTree($treeByParent, $treeByCat, 4, 0) );
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.28 0.004 0.043 12.39 5.4.27 0.010 0.038 12.39 5.4.26 0.003 0.042 12.39 5.4.25 0.006 0.040 12.39 5.4.24 0.010 0.043 12.39 5.4.23 0.006 0.039 12.38 5.4.22 0.008 0.037 12.38 5.4.21 0.007 0.042 12.38 5.4.20 0.009 0.046 12.38 5.4.19 0.006 0.060 12.38 5.4.18 0.015 0.075 12.38 5.4.17 0.009 0.058 12.38 5.4.16 0.008 0.039 12.38 5.4.15 0.009 0.047 12.37 5.4.14 0.005 0.040 12.06 5.4.13 0.006 0.041 12.04 5.4.12 0.009 0.041 12.01 5.4.11 0.006 0.045 12.01 5.4.10 0.010 0.065 12.00 5.4.9 0.011 0.055 12.00 5.4.8 0.009 0.057 12.01 5.4.7 0.008 0.052 12.01 5.4.6 0.013 0.057 12.00 5.4.5 0.009 0.058 12.00 5.4.4 0.012 0.057 11.99 5.4.3 0.010 0.058 11.98 5.4.2 0.019 0.070 11.98 5.4.1 0.009 0.054 11.99 5.4.0 0.013 0.070 11.48 5.3.28 0.008 0.058 12.71 5.3.27 0.014 0.079 12.73 5.3.26 0.015 0.067 12.72 5.3.25 0.008 0.063 12.72 5.3.24 0.011 0.048 12.72 5.3.23 0.014 0.072 12.71 5.3.22 0.013 0.056 12.68 5.3.21 0.011 0.057 12.68 5.3.20 0.008 0.075 12.68 5.3.19 0.015 0.051 12.68 5.3.18 0.006 0.063 12.67 5.3.17 0.012 0.092 12.67 5.3.16 0.006 0.059 12.67 5.3.15 0.009 0.061 12.68 5.3.14 0.015 0.055 12.66 5.3.13 0.006 0.048 12.66 5.3.12 0.008 0.043 12.66 5.3.11 0.005 0.047 12.66 5.3.10 0.006 0.043 12.12 5.3.9 0.012 0.037 12.09 5.3.8 0.009 0.036 12.08 5.3.7 0.005 0.042 12.07 5.3.6 0.009 0.038 12.07 5.3.5 0.011 0.037 12.00 5.3.4 0.006 0.041 12.00 5.3.3 0.009 0.035 11.95 5.3.2 0.008 0.045 11.74 5.3.1 0.013 0.046 11.70 5.3.0 0.011 0.046 11.69
preferences:dark mode live preview
158.82 ms | 1394 KiB | 7 Q