3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'id' => 196, 'name' => 'Abilități spirituale', 'parent' => 0, 'depth' => 0, 'score' => 0, 'sort' => null, ], [ 'id' => 395, 'name' => 'Date generale', 'parent' => 196, 'depth' => 0, 'score' => 0, 'sort' => 1, ], [ 'id' => 201, 'name' => 'Gândirea pozitivă', 'parent' => 197, 'depth' => 0, 'score' => 0, 'sort' => 1, ], [ 'id' => 202, 'name' => 'Satisfacția personală', 'parent' => 197, 'depth' => 0, 'score' => 0, 'sort' => 2, ], [ 'id' => 203, 'name' => 'Concordanța cu sine', 'parent' => 197, 'depth' => 0, 'score' => 0, 'sort' => 3, ], [ 'id' => 204, 'name' => 'Managementul calitativ al timpului liber', 'parent' => 197, 'depth' => 0, 'score' => 0, 'sort' => 4, ], [ 'id' => 198, 'name' => 'Armonia cu ceilalți', 'parent' => 196, 'depth' => 0, 'score' => 0, 'sort' => 3, ], [ 'id' => 199, 'name' => 'Sensul vieții și misiunea personală', 'parent' => 196, 'depth' => 0, 'score' => 0, 'sort' => 4, ], [ 'id' => 200, 'name' => 'Perspectiva de ansamblu asupra realității', 'parent' => 196, 'depth' => 0, 'score' => 0, 'sort' => 5, ], [ 'id' => 197, 'name' => 'Armonia cu sine', 'parent' => 196, 'depth' => 0, 'score' => 0, 'sort' => 2, ], ]; function getScore(int $id): int { return [ 196 => 0, 197 => 0, 198 => 54, 199 => 49, 200 => 49, 201 => 57, 202 => 38, 203 => 29, 204 => 21, 395 => 0, ][$id] ?? 0; } function buildTree(array &$rows, int $parentId = 0, int $depth = 0): array { $tree = []; foreach ($rows as &$row) { if ($row['parent'] !== $parentId) { continue; } $row['depth'] = $depth; $row['children'] = buildTree($rows, $row['id'], $depth + 1); foreach ($row['children'] as &$child) { $row['score'] += $child['score'] += getScore($child['id']); $child['depth'] = $depth + 1; } $tree[] = $row; } return $tree; } usort( $array, fn($a, $b) => $a['sort'] <=> $b['sort'] ); var_export( buildTree($array) );

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)
8.4.140.0140.00717.86
8.4.130.0100.01117.72
8.4.120.0090.00320.65
8.4.110.0140.00622.70
8.4.100.0140.00717.95
8.4.90.0110.00719.00
8.4.80.0080.00517.91
8.4.70.0080.00917.83
8.4.60.0110.00918.96
8.4.50.0120.01117.71
8.4.40.0110.00720.49
8.4.30.0000.00922.09
8.4.20.0040.01818.01
8.4.10.0060.00622.22
8.3.270.0120.00916.66
8.3.260.0130.00616.59
8.3.250.0160.00419.18
8.3.240.0080.01016.76
8.3.230.0150.00416.70
8.3.220.0080.01117.17
8.3.210.0140.00616.64
8.3.200.0040.00616.65
8.3.190.0080.01116.73
8.3.180.0100.00816.84
8.3.170.0040.01117.41
8.3.160.0140.00416.73
8.3.150.0070.01420.60
8.3.140.0000.00816.84
8.3.130.0090.00018.48
8.3.120.0030.00616.84
8.3.110.0180.00016.75
8.3.100.0090.00618.43
8.3.90.0110.00718.15
8.3.80.0030.00618.43
8.3.70.0060.01016.75
8.3.60.0110.00716.75
8.3.50.0080.00817.06
8.3.40.0070.00720.34
8.3.30.0070.01020.96
8.3.20.0050.00324.18
8.3.10.0040.00424.66
8.3.00.0040.00426.16
8.2.290.0060.00220.71
8.2.280.0110.00516.66
8.2.270.0040.00417.56
8.2.260.0000.00819.10
8.2.250.0070.00016.85
8.2.240.0030.00619.07
8.2.230.0070.01120.94
8.2.220.0000.01024.06
8.2.210.0040.00426.77
8.2.200.0000.01116.75
8.2.190.0070.01116.63
8.2.180.0130.00616.63
8.2.170.0090.00619.04
8.2.160.0090.00622.96
8.2.150.0040.00425.66
8.2.140.0000.00824.66
8.2.130.0080.00026.16
8.2.120.0050.00519.51
8.2.110.0090.00021.00
8.2.100.0070.00417.91
8.2.90.0000.00817.91
8.2.80.0060.00318.16
8.2.70.0060.00317.63
8.2.60.0150.00317.13
8.2.50.0110.00717.00
8.2.40.0110.00717.38
8.2.30.0000.01717.63
8.2.20.0100.01017.38
8.2.10.0140.00417.38
8.2.00.0140.00417.50
8.1.330.0100.00522.25
8.1.320.0120.00617.60
8.1.310.0100.00716.73
8.1.300.0090.00019.66
8.1.290.0030.00618.88
8.1.280.0190.00325.92
8.1.270.0030.00524.02
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0080.00023.98
8.1.230.0040.00820.88
8.1.220.0030.00617.74
8.1.210.0050.00318.77
8.1.200.0040.00417.35
8.1.190.0190.00017.25
8.1.180.0180.00017.25
8.1.170.0150.00017.23
8.1.160.0080.00817.25
8.1.150.0120.00616.97
8.1.140.0080.00817.13
8.1.130.0110.00617.13
8.1.120.0120.00617.13
8.1.110.0130.00417.21
8.1.100.0130.00317.38
8.1.90.0120.00317.35
8.1.80.0120.00517.38
8.1.70.0130.00517.38
8.1.60.0150.00417.25
8.1.50.0090.00917.38
8.1.40.0150.00417.50
8.1.30.0150.00317.22
8.1.20.0120.00617.50
8.1.10.0060.01317.25
8.1.00.0110.00617.38
8.0.300.0030.00620.16
8.0.290.0040.00416.88
8.0.280.0170.00016.52
8.0.270.0030.01316.52
8.0.260.0140.00316.52
8.0.250.0160.00016.88
8.0.240.0120.00416.75
8.0.230.0170.00016.52
8.0.220.0170.00016.52
8.0.210.0140.00516.87
8.0.200.0190.00016.63
8.0.190.0140.00216.88
8.0.180.0070.01016.85
8.0.170.0110.00616.75
8.0.160.0110.00516.52
8.0.150.0120.00316.75
8.0.140.0060.01116.86
8.0.130.0160.00016.52
8.0.120.0160.00016.63
8.0.110.0120.00516.52
8.0.100.0170.00016.75
8.0.90.0100.00616.52
8.0.80.0120.00416.63
8.0.70.0170.00016.62
8.0.60.0130.00416.75
8.0.50.0160.00316.75
8.0.30.0130.00416.63
8.0.20.0160.00016.62
8.0.10.0110.00516.63

preferences:
36.4 ms | 403 KiB | 5 Q