3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ /* | */['id' => 1, 'depth' => 1], /* |----| */ ['id' => 19, 'depth' => 2], /* |----|----| */ ['id' => 20, 'depth' => 3], /* |----| */ ['id' => 73, 'depth' => 2], /* | */ ['id' => 3, 'depth' => 1], /* |----| */ ['id' => 25, 'depth' => 2], ]; $root = new stdClass(); $bread_crumbs = [$root]; foreach ($array as $item) { // make it object to simplify access to its parts $object_item = (object) $item; $expected_depth = count($bread_crumbs); if ($object_item->depth < 1) { throw new Exception('Depth cannot be lower than 1'); } elseif ($object_item->depth == $expected_depth) { // doing nothing } elseif ($object_item->depth < $expected_depth) { // remove 'unwanted' items to make expected_depth actual array_splice($bread_crumbs, -($expected_depth - $object_item->depth)); } else { throw new Exception('Error cannot jump too high'); } end($bread_crumbs)->children[] = $object_item; // and then just add to the end of bread_crumbs current object_item $bread_crumbs[] = $object_item; } 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)
8.5.30.0120.00617.42
8.5.20.0080.00820.17
8.5.10.0120.00519.98
8.5.00.0180.00420.11
8.4.180.0190.00520.64
8.4.170.0150.01024.04
8.4.160.0100.01123.99
8.4.150.0070.00516.90
8.4.140.0130.00917.56
8.4.130.0050.00517.93
8.4.120.0050.00420.55
8.4.110.0040.00522.57
8.4.100.0130.00917.87
8.4.90.0110.01017.64
8.4.80.0040.00517.67
8.4.70.0150.00618.10
8.4.60.0030.00618.79
8.4.50.0140.00617.63
8.4.40.0100.01017.71
8.4.30.0160.00417.52
8.4.20.0120.00917.57
8.4.10.0130.00717.47
8.3.300.0170.00822.59
8.3.290.0080.00120.07
8.3.280.0090.01218.36
8.3.270.0130.00716.49
8.3.260.0130.00616.55
8.3.250.0070.01218.93
8.3.240.0120.00916.73
8.3.230.0100.00716.42
8.3.220.0090.00917.12
8.3.210.0140.00616.92
8.3.200.0040.00416.65
8.3.190.0120.00816.86
8.3.180.0090.01116.46
8.3.170.0060.01316.45
8.3.160.0120.00316.67
8.3.150.0070.01317.18
8.3.140.0040.00419.18
8.3.130.0050.00318.54
8.3.120.0090.00018.99
8.3.110.0060.00320.94
8.3.100.0090.00024.06
8.3.90.0080.00026.77
8.3.80.0070.00317.97
8.3.70.0070.01418.43
8.3.60.0210.00016.50
8.3.50.0070.01322.05
8.3.40.0030.01218.68
8.3.30.0110.00418.67
8.3.20.0080.00020.27
8.3.10.0080.00023.71
8.3.00.0040.00417.75
8.2.300.0130.01118.76
8.2.290.0090.00920.36
8.2.280.0070.00418.57
8.2.270.0070.00416.63
8.2.260.0050.01418.89
8.2.250.0120.00616.60
8.2.240.0070.00417.30
8.2.230.0030.00622.58
8.2.220.0030.00537.54
8.2.210.0040.00726.77
8.2.200.0000.01118.54
8.2.190.0110.00716.58
8.2.180.0070.01016.50
8.2.170.0030.01219.04
8.2.160.0070.01522.96
8.2.150.0090.00925.66
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00417.63
8.2.110.0030.00620.53
8.2.100.0080.00418.03
8.2.90.0080.00019.36
8.2.80.0040.00417.97
8.2.70.0030.00517.63
8.2.60.0070.00317.91
8.2.50.0030.00618.07
8.2.40.0050.00320.94
8.2.30.0000.00720.50
8.2.20.0000.00717.75
8.2.10.0070.00018.00
8.2.00.0030.00518.11
8.1.340.0090.01221.73
8.1.330.0080.01116.56
8.1.320.0130.00816.04
8.1.310.0060.01216.77
8.1.300.0040.00418.52
8.1.290.0060.00330.84
8.1.280.0090.00925.92
8.1.270.0050.00323.92
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0100.00317.48
8.1.230.0070.00420.91
8.1.220.0030.00517.74
8.1.210.0080.00018.77
8.1.200.0050.00517.35
8.1.190.0050.00317.25
8.1.180.0050.00318.10
8.1.170.0090.00018.96
8.1.160.0040.00422.06
8.1.150.0000.00818.94
8.1.140.0030.00519.62
8.1.130.0030.00317.63
8.1.120.0040.00417.37
8.1.110.0050.00217.47
8.1.100.0040.00417.41
8.1.90.0040.00417.48
8.1.80.0070.00017.51
8.1.70.0070.00017.38
8.1.60.0040.00417.49
8.1.50.0080.00017.56
8.1.40.0040.00417.40
8.1.30.0040.00717.53
8.1.20.0030.00517.70
8.1.10.0030.00517.59
8.1.00.0040.00417.41
8.0.300.0000.00818.77
8.0.290.0000.00716.75
8.0.280.0020.00518.45
8.0.270.0000.00817.17
8.0.260.0000.00617.18
8.0.250.0070.00016.99
8.0.240.0000.00716.87
8.0.230.0040.00416.92
8.0.220.0000.00816.91
8.0.210.0040.00416.91
8.0.200.0040.00416.94
8.0.190.0030.00616.96
8.0.180.0000.00716.80
8.0.170.0040.00416.78
8.0.160.0080.00016.86
8.0.150.0000.00716.82
8.0.140.0000.00716.75
8.0.130.0000.00513.38
8.0.120.0050.00316.83
8.0.110.0080.00016.85
8.0.100.0000.00716.90
8.0.90.0040.00416.96
8.0.80.0040.01116.96
8.0.70.0000.00716.99
8.0.60.0000.00716.89
8.0.50.0040.00416.96
8.0.30.0120.00917.09
8.0.20.0110.00817.40
8.0.10.0080.00016.96
8.0.00.0130.00516.76
7.4.330.0000.00515.14
7.4.320.0100.00016.65
7.4.300.0040.00416.45
7.4.290.0030.00316.61
7.4.280.0020.00516.52
7.4.270.0000.00816.50
7.4.260.0000.01016.63
7.4.250.0000.00716.58
7.4.240.0000.00916.63
7.4.230.0030.00316.46
7.4.220.0040.01416.55
7.4.210.0080.00916.48
7.4.200.0080.00016.68
7.4.160.0100.00716.36
7.4.150.0110.00917.40
7.4.140.0190.00617.86
7.4.130.0110.00916.61
7.4.120.0110.00816.54
7.4.110.0110.01116.46
7.4.100.0090.00916.41
7.4.90.0090.01316.52
7.4.80.0100.01019.39
7.4.70.0040.01416.66
7.4.60.0120.00616.55
7.4.50.0040.00416.47
7.4.40.0110.00616.64
7.4.30.0150.00916.59
7.4.00.0100.00614.99
7.3.330.0030.00313.10
7.3.320.0050.00213.11
7.3.310.0000.00716.21
7.3.300.0040.00416.17
7.3.290.0030.00316.29
7.3.280.0090.00816.28
7.3.270.0130.01017.40
7.3.260.0110.00816.31
7.3.250.0120.00716.31
7.3.240.0100.00816.46
7.3.230.0080.00816.42
7.3.210.0100.00916.30
7.3.200.0000.01816.54
7.3.190.0060.01216.36
7.3.180.0130.00316.32
7.3.170.0030.01316.59
7.3.160.0070.01716.56
7.3.120.0070.01114.61
7.3.110.0030.01414.50
7.3.100.0030.01314.54
7.3.90.0060.00314.91
7.3.80.0070.00714.81
7.3.70.0090.00614.84
7.3.60.0080.00814.76
7.3.50.0030.00614.68
7.3.40.0070.00314.54
7.3.30.0110.00414.84
7.3.20.0040.00416.84
7.3.10.0050.00716.58
7.3.00.0030.01016.56
7.2.330.0100.00916.61
7.2.320.0070.01716.71
7.2.310.0060.01316.57
7.2.300.0140.00516.86
7.2.290.0170.00316.80
7.2.250.0060.01314.86
7.2.240.0060.01315.10
7.2.230.0070.01015.05
7.2.220.0000.01114.97
7.2.210.0030.01315.28
7.2.200.0070.00714.95
7.2.190.0000.01614.80
7.2.180.0040.00815.08
7.2.170.0090.00315.08
7.2.130.0000.01416.96
7.2.120.0000.00916.88
7.2.110.0000.00817.02
7.2.100.0000.01316.77
7.2.90.0060.00617.10
7.2.80.0060.00316.61
7.2.70.0060.00816.83
7.2.60.0090.00516.75
7.2.50.0060.00616.89
7.2.40.0040.01116.93
7.2.30.0100.00317.02
7.2.20.0060.01016.78
7.2.10.0060.00316.87
7.2.00.0090.00616.86
7.1.330.0030.01015.53
7.1.320.0030.01015.82
7.1.310.0140.00015.67
7.1.300.0030.01015.77
7.1.290.0060.00615.84
7.1.280.0000.01415.55
7.1.270.0070.00715.75
7.1.260.0000.00915.88
7.1.250.0070.01015.75
7.1.200.0060.00615.77
7.1.70.0040.00417.25
7.1.60.0030.02219.43
7.1.50.0100.01316.79
7.1.00.0030.07322.32
7.0.200.0360.00014.76
7.0.60.0100.07721.70
7.0.50.0070.04717.87
7.0.40.0100.07019.98
7.0.30.0270.06720.01
7.0.20.0300.03320.18
7.0.10.0070.06020.30
7.0.00.0000.04320.09
5.6.280.0030.07321.05
5.6.210.0130.07320.52
5.6.200.0070.06018.16
5.6.190.0070.04320.64
5.6.180.3430.04720.58
5.6.170.0300.05320.52
5.6.160.0030.09320.61
5.6.150.0100.07718.18
5.6.140.0170.06718.17
5.6.130.0030.08318.18
5.6.120.0100.08021.05
5.6.110.0130.07721.02
5.6.100.0070.04320.97
5.6.90.0100.08320.99
5.6.80.0070.08320.29
5.5.350.3130.04320.51
5.5.340.0070.04018.02
5.5.330.0030.09020.23
5.5.320.0300.04320.23
5.5.310.0270.07320.50
5.5.300.0100.08017.96
5.5.290.0100.04018.00
5.5.280.0100.08020.85
5.5.270.0000.06720.87
5.5.260.0130.06720.73
5.5.250.0030.04020.45
5.5.240.0300.06320.13
5.4.450.0230.04719.13
5.4.440.0100.06319.46
5.4.430.0130.05719.40
5.4.420.0200.05019.43
5.4.410.0230.05018.99
5.4.400.0170.04719.14
5.4.390.0270.05719.16
5.4.380.0200.04318.95
5.4.370.0130.05019.13
5.4.360.0170.05718.78
5.4.350.0130.05318.95
5.4.340.0200.05019.10
5.4.320.0170.05719.24
5.4.310.0100.05018.96
5.4.300.0200.04019.19
5.4.290.0630.03719.15
5.4.280.0170.07019.23
5.4.270.0170.04719.09
5.4.260.0400.05019.19
5.4.250.0070.05718.74
5.4.240.0100.05318.98
5.4.230.0300.05318.91
5.4.220.0030.06019.07
5.4.210.0200.04318.98
5.4.200.0070.06718.79
5.4.190.0270.05319.23
5.4.180.0300.04319.07
5.4.170.0370.05018.91
5.4.160.0270.05718.89
5.4.150.0130.05319.11
5.4.140.0070.05316.61
5.4.130.0130.04716.50
5.4.120.0530.04016.60
5.4.110.0600.05016.29
5.4.100.0530.05016.56
5.4.90.0070.05016.36
5.4.80.0630.04016.49
5.4.70.0100.05016.36
5.4.60.0070.05716.27
5.4.50.0270.04716.16
5.4.40.0170.05716.48
5.4.30.0130.05016.42
5.4.20.0200.06016.45
5.4.10.0270.06316.16
5.4.00.0170.05315.93

preferences:
51 ms | 2151 KiB | 5 Q