3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( 55 => array( 'ident' => 'test 1', 'depth' => 1, ), 77 => array( 'parent_id' => 55, 'ident' => 'test 2', 'depth' => 2, ), 109 => array( 'parent_id' => 77, 'ident' => 'test 3', 'depth' => 3, ), 78 => array( 'parent_id' => 55, 'ident' => 'test 4', 'depth' => 2, ), 25 => array( 'ident' => 'test 5', 'depth' => 1, ) ); function v1($array) { foreach ($array as $key => &$sub) { if (isset($sub['parent_id'])) { $array[$sub['parent_id']]['children'][$key] = &$sub; } } unset($sub); // unset the reference to make sure to not overwrite it later... // now remove the entries with parents foreach ($array as $key => $sub) { if (isset($sub['parent_id'])) unset($array[$key]); } return $array; } function push_at_key($what, $what_key, $key, $array) { foreach($array as $k => $v) { if($key == $k) { $array[$k]['children'][$what_key] = $what; return $array; } } //foreach($array as $sub) { // if(isset($sub['children']) && FALSE !== ($found = push_at_key($what, $what_key, $key, $sub['children']))) { // return $found; // } //} return FALSE; } function v2($array) { $out = array(); foreach ($array as $key => $sub) { if(!isset($sub['parent_id'])) { $out[$key] = $sub; } else { $out = push_at_key($sub, $key, $sub['parent_id'], $out); } } return $out; } //var_dump(v1($array)); var_dump(v2($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.3.60.0160.00618.55
8.3.50.0220.00922.05
8.3.40.0070.01418.74
8.3.30.0110.00419.04
8.3.20.0070.00720.07
8.3.10.0000.00722.09
8.3.00.0040.00422.52
8.2.180.0140.00316.63
8.2.170.0110.00322.96
8.2.160.0070.00720.98
8.2.150.0000.00824.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0030.00617.88
8.2.110.0000.01022.11
8.2.100.0000.01119.70
8.2.90.0050.00318.98
8.2.80.0000.00819.66
8.2.70.0030.00617.63
8.2.60.0040.00418.03
8.2.50.0030.00618.07
8.2.40.0060.00318.00
8.2.30.0000.00818.15
8.2.20.0040.00417.77
8.2.10.0000.00717.76
8.2.00.0050.00317.87
8.1.280.0040.01225.92
8.1.270.0050.00322.25
8.1.260.0070.00026.35
8.1.250.0030.00528.09
8.1.240.0060.00323.83
8.1.230.0040.00819.10
8.1.220.0040.00417.79
8.1.210.0000.00918.77
8.1.200.0040.00817.35
8.1.190.0000.00817.68
8.1.180.0030.00618.10
8.1.170.0030.00618.71
8.1.160.0000.00822.01
8.1.150.0030.00518.69
8.1.140.0040.00417.48
8.1.130.0030.00517.88
8.1.120.0000.00717.52
8.1.110.0050.00217.48
8.1.100.0000.00717.38
8.1.90.0030.00317.41
8.1.80.0000.00717.45
8.1.70.0030.00317.44
8.1.60.0030.00517.53
8.1.50.0030.00517.46
8.1.40.0050.00317.43
8.1.30.0030.00617.57
8.1.20.0060.00317.66
8.1.10.0040.00417.45
8.1.00.0040.00417.38
8.0.300.0000.00718.77
8.0.290.0040.00417.30
8.0.280.0040.00418.50
8.0.270.0030.00317.20
8.0.260.0000.00816.84
8.0.250.0000.00717.07
8.0.240.0000.00816.96
8.0.230.0000.00717.01
8.0.220.0040.00416.96
8.0.210.0070.00017.02
8.0.200.0000.00717.05
8.0.190.0000.00817.07
8.0.180.0040.00417.02
8.0.170.0040.00417.08
8.0.160.0060.00317.01
8.0.150.0000.00717.01
8.0.140.0080.00016.97
8.0.130.0000.00613.42
8.0.120.0040.00416.89
8.0.110.0050.00217.04
8.0.100.0000.00716.96
8.0.90.0000.00717.06
8.0.80.0120.00616.96
8.0.70.0020.00516.85
8.0.60.0040.00417.01
8.0.50.0030.00516.96
8.0.30.0120.00717.20
8.0.20.0150.00517.40
8.0.10.0000.00716.89
8.0.00.0130.00516.92
7.4.330.0030.00315.00
7.4.320.0000.00716.55
7.4.300.0000.00816.67
7.4.290.0030.00616.63
7.4.280.0000.00716.45
7.4.270.0030.00516.44
7.4.260.0000.00716.43
7.4.250.0020.00516.65
7.4.240.0060.00216.55
7.4.230.0040.00416.45
7.4.220.0110.00616.55
7.4.210.0080.00916.64
7.4.200.0000.00716.55
7.4.190.0030.00316.72
7.4.160.0080.00816.76
7.4.150.0200.00017.40
7.4.140.0150.00417.86
7.4.130.0080.01116.56
7.4.120.0070.00916.61
7.4.110.0130.00316.68
7.4.100.0090.00916.50
7.4.90.0030.01416.48
7.4.80.0060.01219.39
7.4.70.0140.00516.52
7.4.60.0040.01216.44
7.4.50.0030.00516.26
7.4.40.0070.01022.77
7.4.30.0090.00916.69
7.4.10.0070.01115.13
7.4.00.0070.01214.82
7.3.330.0000.00613.23
7.3.320.0000.00513.21
7.3.310.0000.00716.50
7.3.300.0030.00316.47
7.3.290.0060.01116.49
7.3.280.0070.00816.44
7.3.270.0150.00317.40
7.3.260.0070.01016.50
7.3.250.0070.01316.52
7.3.240.0090.00916.45
7.3.230.0060.01116.44
7.3.210.0070.01216.45
7.3.200.0000.01719.39
7.3.190.0130.00616.57
7.3.180.0100.01016.61
7.3.170.0110.00616.42
7.3.160.0130.00316.44
7.3.130.0130.00714.95
7.3.120.0020.01514.74
7.3.110.0070.01014.98
7.3.100.0060.00914.79
7.3.90.0060.00614.94
7.3.80.0060.00315.16
7.3.70.0000.01315.05
7.3.60.0030.00614.76
7.3.50.0140.00014.95
7.3.40.0100.00715.00
7.3.30.0120.00314.86
7.3.20.0060.00616.66
7.3.10.0000.01216.55
7.3.00.0080.00516.57
7.2.330.0070.01016.85
7.2.320.0090.00916.48
7.2.310.0150.00316.56
7.2.300.0060.01116.48
7.2.290.0100.00716.84
7.2.260.0130.00315.27
7.2.250.0070.01315.05
7.2.240.0130.00315.33
7.2.230.0100.00715.02
7.2.220.0120.00314.95
7.2.210.0060.00614.95
7.2.200.0070.00715.34
7.2.190.0100.00015.20
7.2.180.0030.01314.96
7.2.170.0080.00414.98
7.2.160.0090.00614.86
7.2.150.0060.00916.72
7.2.140.0070.00716.75
7.2.130.0050.00716.94
7.2.120.0050.00616.98
7.2.110.0050.00917.03
7.2.100.0090.00316.91
7.2.90.0080.00516.99
7.2.80.0090.00717.06
7.2.70.0020.00816.88
7.2.60.0050.00916.75
7.2.50.0070.00516.94
7.2.40.0030.01316.76
7.2.30.0020.01216.92
7.2.20.0040.00816.84
7.2.10.0040.00916.96
7.2.00.0050.01017.82
7.1.330.0070.00715.63
7.1.320.0050.00815.57
7.1.310.0040.00815.63
7.1.300.0120.00315.63
7.1.290.0070.00715.70
7.1.280.0000.01115.80
7.1.270.0030.01015.95
7.1.260.0100.00315.75
7.1.250.0050.00915.76
7.1.240.0030.00815.78
7.1.230.0050.00915.78
7.1.220.0020.00915.81
7.1.210.0030.01215.75
7.1.200.0030.01215.76
7.1.190.0080.00515.85
7.1.180.0060.01115.82
7.1.170.0040.00915.79
7.1.160.0070.00515.87
7.1.150.0000.01415.56
7.1.140.0060.00815.59
7.1.130.0020.01215.72
7.1.120.0020.00815.88
7.1.110.0050.00815.80
7.1.100.0040.01116.58
7.1.90.0060.00515.88
7.1.80.0050.00715.69
7.1.70.0060.00416.21
7.1.60.0120.00517.16
7.1.50.0060.01115.98
7.1.40.0060.00915.85
7.1.30.0050.00815.80
7.1.20.0050.00615.78
7.1.10.0070.00815.79
7.1.00.0060.02918.02
7.0.330.0060.00715.11
7.0.320.0050.00815.50
7.0.310.0020.01115.53
7.0.300.0070.00715.37
7.0.290.0040.00915.36
7.0.280.0020.00815.23
7.0.270.0040.00915.46
7.0.260.0030.00615.45
7.0.250.0050.00815.51
7.0.240.0100.00515.52
7.0.230.0040.00915.46
7.0.220.0030.01015.39
7.0.210.0060.00515.21
7.0.200.0050.00615.83
7.0.190.0060.00615.38
7.0.180.0050.00715.37
7.0.170.0040.00915.47
7.0.160.0060.00415.45
7.0.150.0070.00515.37
7.0.140.0020.03217.65
7.0.130.0080.00615.47
7.0.120.0060.00915.25
7.0.110.0040.00815.45
7.0.100.0150.02916.97
7.0.90.0190.02116.88
7.0.80.0180.03316.99
7.0.70.0190.02016.80
7.0.60.0160.01916.92
7.0.50.0110.03317.06
7.0.40.0050.03115.70
7.0.30.0100.02915.76
7.0.20.0110.02615.65
7.0.10.0040.03315.75
7.0.00.0050.02415.65
5.6.400.0000.01114.39
5.6.390.0080.00414.17
5.6.380.0070.01014.42
5.6.370.0040.00914.23
5.6.360.0060.00614.56
5.6.350.0050.00514.44
5.6.340.0010.00914.43
5.6.330.0090.00414.47
5.6.320.0070.00514.51
5.6.310.0030.01014.50
5.6.300.0080.00514.50
5.6.290.0090.00714.30
5.6.280.0040.03016.83
5.6.270.0120.00214.49
5.6.260.0140.00214.36
5.6.250.0060.02316.48
5.6.240.0100.03316.59
5.6.230.0080.03016.46
5.6.220.0090.02616.50
5.6.210.0040.03216.56
5.6.200.0050.03316.74
5.6.190.0020.03716.65
5.6.180.0050.03516.64
5.6.170.0100.02716.58
5.6.160.0050.03316.61
5.6.150.0070.03416.67
5.6.140.0080.02916.80
5.6.130.0060.03616.58
5.6.120.0070.03516.65
5.6.110.0080.03016.65
5.6.100.0070.02016.54
5.6.90.0070.03016.71
5.6.80.0070.03016.29
5.6.70.0050.02116.42
5.6.60.0060.02916.22
5.6.50.0030.03616.30
5.6.40.0070.02916.34
5.6.30.0080.03016.26
5.6.20.0100.02816.27
5.6.10.0060.02016.25
5.6.00.0060.03216.39
5.5.380.0040.03315.41
5.5.370.0080.02515.37
5.5.360.0070.02615.27
5.5.350.0060.03315.55
5.5.340.0080.03015.51
5.5.330.0080.02815.60
5.5.320.0040.02515.56
5.5.310.0030.02915.47
5.5.300.0030.03315.49
5.5.290.0110.02415.54
5.5.280.0050.03115.38
5.5.270.0100.02915.42
5.5.260.0060.02815.38
5.5.250.0080.02515.38
5.5.240.0070.02915.30
5.5.230.0050.02015.25
5.5.220.0090.02715.22
5.5.210.0060.02415.15
5.5.200.0100.02715.23
5.5.190.0130.02715.25
5.5.180.0070.03315.28
5.5.170.0090.00412.68
5.5.160.0080.03115.19
5.5.150.0090.03015.26
5.5.140.0040.03015.34
5.5.130.0070.03115.29
5.5.120.0070.02815.40
5.5.110.0040.01715.13
5.5.100.0040.01915.23
5.5.90.0060.01615.07
5.5.80.0100.01415.18
5.5.70.0070.01715.20
5.5.60.0030.01915.30
5.5.50.0030.01815.26
5.5.40.0040.01715.16
5.5.30.0080.02115.12
5.5.20.0030.01615.19
5.5.10.0060.02415.06
5.5.00.0020.01915.02
5.4.450.0100.02914.43
5.4.440.0060.02914.46
5.4.430.0040.03114.39
5.4.420.0080.02914.34
5.4.410.0050.02914.38
5.4.400.0100.02714.32
5.4.390.0060.02514.23
5.4.380.0050.02914.31
5.4.370.0120.02414.31
5.4.360.0040.03114.21
5.4.350.0080.02214.34
5.4.340.0080.01714.33
5.4.330.0020.00811.73
5.4.320.0060.02914.28
5.4.310.0080.02514.32
5.4.300.0080.02814.27
5.4.290.0080.02414.30
5.4.280.0090.02914.30
5.4.270.0020.02114.25
5.4.260.0040.01814.27
5.4.250.0080.01614.33
5.4.240.0020.01914.16
5.4.230.0020.01914.20
5.4.220.0020.01514.28
5.4.210.0050.01714.27
5.4.200.0030.01714.33
5.4.190.0040.01814.34
5.4.180.0010.02014.28
5.4.170.0070.01514.19
5.4.160.0020.01814.21
5.4.150.0090.01714.30
5.4.140.0040.02913.40
5.4.130.0030.01713.40
5.4.120.0060.01413.29
5.4.110.0050.01613.48
5.4.100.0040.01513.39
5.4.90.0030.01613.32
5.4.80.0060.01513.42
5.4.70.0070.01313.45
5.4.60.0030.01513.35
5.4.50.0030.01613.49
5.4.40.0070.01413.41
5.4.30.0020.01713.51
5.4.20.0030.01513.34
5.4.10.0030.01713.38
5.4.00.0030.02013.03
5.3.290.0000.02412.68
5.3.280.0010.01912.63
5.3.270.0030.01612.67
5.3.260.0070.01512.65
5.3.250.0040.01912.60
5.3.240.0040.01612.64
5.3.230.0030.01612.66
5.3.220.0010.01912.61
5.3.210.0060.01612.70
5.3.200.0040.01712.68
5.3.190.0030.01612.67
5.3.180.0030.01812.68
5.3.170.0050.02812.73
5.3.160.0050.01512.72
5.3.150.0040.01612.68
5.3.140.0100.00912.66
5.3.130.0020.02212.61
5.3.120.0050.01312.64
5.3.110.0010.01912.55
5.3.100.0060.01312.59
5.3.90.0030.01612.53
5.3.80.0020.01912.49
5.3.70.0020.01912.43
5.3.60.0060.01512.46
5.3.50.0030.01712.44
5.3.40.0060.01412.43
5.3.30.0050.01512.43
5.3.20.0030.02512.32
5.3.10.0030.01712.29
5.3.00.0030.01712.27
5.2.170.0040.01510.39
5.2.160.0050.01810.40
5.2.150.0040.01810.28
5.2.140.0020.01810.24
5.2.130.0030.01810.29
5.2.120.0030.01610.39
5.2.110.0070.02010.37
5.2.100.0020.02210.36
5.2.90.0060.02010.37
5.2.80.0020.02210.34
5.2.70.0080.03110.29
5.2.60.0070.03110.24
5.2.50.0070.03010.30
5.2.40.0040.02910.27
5.2.30.0040.02810.26
5.2.20.0060.03210.19
5.2.10.0020.03510.09
5.2.00.0050.02010.03
5.1.60.0030.0289.75
5.1.50.0000.0329.74
5.1.40.0050.0289.71
5.1.30.0050.0189.92
5.1.20.0010.0309.94
5.1.10.0030.0319.80
5.1.00.0050.0229.74
5.0.50.0030.0179.10
5.0.40.0030.0249.10
5.0.30.0040.0349.10
5.0.20.0040.0209.10
5.0.10.0020.0239.10
5.0.00.0050.0349.10
4.4.90.0010.0109.10
4.4.80.0030.0189.10
4.4.70.0000.0209.10
4.4.60.0030.0199.10
4.4.50.0050.0189.10
4.4.40.0030.0319.10
4.4.30.0020.0209.10
4.4.20.0030.0169.10
4.4.10.0040.0209.10
4.4.00.0000.0189.10
4.3.110.0030.0219.10
4.3.100.0020.0189.10
4.3.90.0020.0199.10
4.3.80.0000.0319.10
4.3.70.0050.0129.10
4.3.60.0080.0139.10
4.3.50.0030.0199.10
4.3.40.0080.0239.10
4.3.30.0020.0109.10
4.3.20.0000.0229.10
4.3.10.0000.0219.10
4.3.00.0020.0199.10

preferences:
44.42 ms | 401 KiB | 5 Q