@ 2018-06-02T11:06:29Z <?php
$categories = array(
array(
'parent_id' => 0,
'categories_id' => 1,
),
array(
'parent_id' => 1,
'categories_id' => 11,
),
array(
'parent_id' => 1,
'categories_id' => 111,
),
array(
'parent_id' => 0,
'categories_id' => 2,
),
array(
'parent_id' => 2,
'categories_id' => 22,
),
);
$tree = array();
foreach ($categories as $category) {
$tree = &build(&$tree, $category);
}
// var_export($tree);
function &build(&$tree = array(), $category) {
if (empty($category)) {
return;
}
if ($category['parent_id'] == 0 && ! isset($category['childs'])) {
$category = array_merge($category, array('childs' => array()));
$tree = array_merge($tree, $category);
return $tree;
}
foreach ($tree as $parent_id => $cate) {
var_dump($tree);
if ($category['parent_id'] == $parent_id) {
$cate[$parent_id]['childs'] = $category;
}
if (is_array($cate)) {
return build($tree, $category);
}
}
return $tree;
}
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) 7.2.6 0.130 0.006 14.70 7.2.5 0.088 0.009 14.76 7.2.4 0.102 0.010 15.34 7.2.3 0.127 0.011 15.07 7.2.2 0.125 0.010 15.08 7.2.1 0.095 0.007 15.03 7.2.0 0.116 0.010 14.93 7.1.17 0.083 0.006 13.62 7.1.16 0.115 0.008 16.54 7.1.15 0.119 0.017 16.56 7.1.14 0.114 0.006 16.59 7.1.13 0.194 0.007 16.57 7.1.12 0.097 0.010 16.33 7.1.11 0.133 0.014 16.02 7.1.10 0.108 0.007 15.89 7.1.9 0.147 0.016 15.88 7.1.8 0.158 0.011 15.74 7.1.7 0.125 0.012 14.75 7.1.6 0.188 0.013 33.20 7.1.5 0.152 0.018 32.88 7.1.4 0.145 0.017 32.65 7.1.3 0.187 0.020 32.66 7.1.2 0.137 0.015 32.65 7.1.1 0.145 0.011 14.40 7.1.0 0.127 0.012 14.50
preferences:dark mode live preview
141.03 ms | 1394 KiB | 7 Q