3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

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).

VersionSystem time (s)User time (s)Memory (MiB)
7.0.00.0070.06020.08
5.6.160.0000.05720.71
5.6.150.0100.06318.15
5.6.140.0070.07018.25
5.6.130.0100.06018.23
5.6.120.0070.08720.96
5.6.110.0130.08020.99
5.6.100.0100.07020.98
5.6.90.0170.03320.97
5.6.80.0070.08320.50
5.5.300.0130.06717.97
5.5.290.0070.04018.05
5.5.280.0100.07320.68
5.5.270.0130.07320.86
5.5.260.0070.05720.84
5.5.250.0100.08020.57
5.5.240.0330.06720.25

preferences:
142.4 ms | 1394 KiB | 7 Q