@ 2015-12-04T15:24:48Z <?php
declare(strict_types=1);
$items = [
(object)['id' => 0, 'name' => "root"]
(object)['id' => 1, 'parentId' => 0, 'name' => "foo"],
(object)['id' => 2, 'parentId' => 1, 'name' => "bar"],
(object)['id' => 3, 'parentId' => 1, 'name' => "qux"],
(object)['id' => 4, 'parentId' => 3, 'name' => "zip"],
(object)['id' => 5, 'parentId' => 4, 'name' => "baz"]
];
$itemsById = [];
foreach ($items as $item) {
$itemsById[$item->id] = $item;
}
// ---
foreach ($itemsById as $id => $item) {
if (isset($item->parentId)) {
$itemsById[$item->parentId]->children[] = $item;
}
}
$root = $itemsById[0];
var_dump($root);
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.0.0 0.007 0.060 20.08 5.6.16 0.000 0.057 20.71 5.6.15 0.010 0.063 18.15 5.6.14 0.007 0.070 18.25 5.6.13 0.010 0.060 18.23 5.6.12 0.007 0.087 20.96 5.6.11 0.013 0.080 20.99 5.6.10 0.010 0.070 20.98 5.6.9 0.017 0.033 20.97 5.6.8 0.007 0.083 20.50 5.5.30 0.013 0.067 17.97 5.5.29 0.007 0.040 18.05 5.5.28 0.010 0.073 20.68 5.5.27 0.013 0.073 20.86 5.5.26 0.007 0.057 20.84 5.5.25 0.010 0.080 20.57 5.5.24 0.033 0.067 20.25
preferences:dark mode live preview
142.4 ms | 1394 KiB | 7 Q