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 $k => $v) { $array[$k] = push_at_key($what, $what_key, $key, $v['children']); } return $array; } 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.0140.00718.18
8.3.50.0140.00822.05
8.3.40.0090.00918.89
8.3.30.0060.00918.70
8.3.20.0040.00418.73
8.3.10.0030.00521.18
8.3.00.0100.00018.91
8.2.180.0120.00916.63
8.2.170.0110.00722.96
8.2.160.0100.00320.40
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0060.00321.07
8.2.110.0090.00020.54
8.2.100.0080.00317.72
8.2.90.0000.00819.17
8.2.80.0000.00917.97
8.2.70.0050.00517.50
8.2.60.0090.00018.05
8.2.50.0090.00018.07
8.2.40.0000.00818.34
8.2.30.0040.00421.28
8.2.20.0080.00017.75
8.2.10.0070.00017.68
8.2.00.0000.00917.68
8.1.280.0090.00625.92
8.1.270.0060.00323.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0100.00022.59
8.1.230.0080.00420.79
8.1.220.0000.00818.77
8.1.210.0000.00818.89
8.1.200.0040.00417.35
8.1.190.0030.00517.52
8.1.180.0040.00418.10
8.1.170.0050.00318.56
8.1.160.0000.00718.91
8.1.150.0000.00718.65
8.1.140.0040.00417.44
8.1.130.0040.00417.86
8.1.120.0080.00017.56
8.1.110.0000.00717.48
8.1.100.0060.00317.50
8.1.90.0040.00417.50
8.1.80.0040.00417.38
8.1.70.0070.00017.48
8.1.60.0080.00017.59
8.1.50.0080.00017.53
8.1.40.0000.00817.58
8.1.30.0040.00417.65
8.1.20.0040.00417.66
8.1.10.0000.01017.48
8.1.00.0000.00717.32
8.0.300.0040.00420.02
8.0.290.0040.00417.18
8.0.280.0040.00418.52
8.0.270.0000.00717.20
8.0.260.0070.00016.85
8.0.250.0000.00816.99
8.0.240.0040.00416.96
8.0.230.0000.00817.00
8.0.220.0030.00316.81
8.0.210.0000.00716.82
8.0.200.0030.00316.97
8.0.190.0060.00316.87
8.0.180.0040.00416.88
8.0.170.0030.00516.87
8.0.160.0040.00416.94
8.0.150.0040.00416.93
8.0.140.0070.00016.91
8.0.130.0000.00713.31
8.0.120.0040.00416.86
8.0.110.0030.00616.95
8.0.100.0000.00716.91
8.0.90.0030.00516.86
8.0.80.0130.00316.96
8.0.70.0000.00716.96
8.0.60.0040.00416.81
8.0.50.0050.00217.01
8.0.30.0090.01416.95
8.0.20.0160.00717.40
8.0.10.0000.00716.91
8.0.00.0110.01116.76
7.4.330.0030.00316.67
7.4.320.0040.00416.62
7.4.300.0000.00616.64
7.4.290.0000.00716.53
7.4.280.0040.00416.66
7.4.270.0030.00316.55
7.4.260.0030.00313.25
7.4.250.0000.00816.55
7.4.240.0000.00716.69
7.4.230.0070.00016.72
7.4.220.0030.01516.58
7.4.210.0100.00716.65
7.4.200.0000.00816.38
7.4.190.0030.00316.72
7.4.160.0090.00916.38
7.4.150.0100.01017.40
7.4.140.0110.01117.86
7.4.130.0190.01916.51
7.4.120.0110.01016.50
7.4.110.0090.00816.51
7.4.100.0040.01816.55
7.4.90.0160.00316.44
7.4.80.0080.01119.39
7.4.70.0090.00916.70
7.4.60.0070.01016.53
7.4.50.0020.00216.38
7.4.40.0060.00922.77
7.4.30.0130.00716.26
7.4.10.0130.00314.75
7.4.00.0050.00914.98
7.3.330.0040.00413.38
7.3.320.0000.00513.32
7.3.310.0000.00816.36
7.3.300.0070.00016.20
7.3.290.0040.01016.35
7.3.280.0140.00516.34
7.3.270.0160.01317.40
7.3.260.0080.01118.24
7.3.250.0100.00716.38
7.3.240.0100.00716.48
7.3.230.0040.01316.59
7.3.210.0060.01116.54
7.3.200.0090.01519.39
7.3.190.0060.01616.37
7.3.180.0090.00916.44
7.3.170.0060.01016.45
7.3.160.0040.01316.39
7.3.130.0140.00314.99
7.3.120.0050.00914.86
7.3.110.0120.00915.13
7.3.100.0070.00714.71
7.3.90.0040.01214.77
7.3.80.0130.00014.79
7.3.70.0060.00814.79
7.3.60.0070.00314.85
7.3.50.0090.00614.97
7.3.40.0090.00614.56
7.3.30.0060.00614.77
7.3.20.0000.01416.46
7.3.10.0080.00516.54
7.3.00.0070.00616.67
7.2.330.0110.01116.74
7.2.320.0170.00016.85
7.2.310.0070.01716.63
7.2.300.0040.01316.82
7.2.290.0080.00816.74
7.2.260.0130.00314.93
7.2.250.0030.01615.29
7.2.240.0100.00615.17
7.2.230.0140.00315.33
7.2.220.0070.00715.24
7.2.210.0000.01215.35
7.2.200.0070.00415.14
7.2.190.0080.00814.91
7.2.180.0140.00315.22
7.2.170.0070.00715.08
7.2.160.0030.01315.09
7.2.150.0000.01716.84
7.2.140.0070.01017.07
7.2.130.0100.00516.95
7.2.120.0090.00916.88
7.2.110.0140.00416.77
7.2.100.0150.00416.82
7.2.90.0100.00916.75
7.2.80.0090.00616.95
7.2.70.0130.00816.90
7.2.60.0060.01216.74
7.2.50.0110.00516.76
7.2.40.0080.00716.80
7.2.30.0100.00616.83
7.2.20.0120.00516.78
7.2.10.0110.00616.83
7.2.00.0050.01017.45
7.1.330.0110.00415.85
7.1.320.0000.00915.78
7.1.310.0040.01115.73
7.1.300.0100.00715.87
7.1.290.0030.01415.64
7.1.280.0070.00715.96
7.1.270.0120.00315.96
7.1.260.0030.01515.87
7.1.250.0060.00515.61
7.1.240.0080.00816.04
7.1.230.0000.01215.55
7.1.220.0090.00615.55
7.1.210.0060.00615.71
7.1.200.0040.01115.67
7.1.190.0110.00315.54
7.1.180.0040.00715.91
7.1.170.0060.00615.98
7.1.160.0000.00815.84
7.1.150.0060.00615.78
7.1.140.0060.01015.68
7.1.130.0060.00915.94
7.1.120.0070.01015.91
7.1.110.0090.00915.93
7.1.100.0030.01116.97
7.1.90.0030.00915.82
7.1.80.0000.01515.97
7.1.70.0050.00816.35
7.1.60.0060.00816.47
7.1.50.0060.01016.29
7.1.40.0060.00615.84
7.1.30.0030.00615.79
7.1.20.0000.00815.88
7.1.10.0070.00715.70
7.1.00.0030.04018.95
7.0.330.0130.00015.18
7.0.320.0060.00615.40
7.0.310.0090.00615.54
7.0.300.0040.01215.14
7.0.290.0030.01015.47
7.0.280.0060.00315.51
7.0.270.0060.00615.45
7.0.260.0090.00915.45
7.0.250.0030.01415.36
7.0.240.0000.01415.13
7.0.230.0030.01015.28
7.0.220.0030.00615.39
7.0.210.0040.00715.48
7.0.200.0040.00916.10
7.0.190.0060.00615.49
7.0.180.0100.00315.52
7.0.170.0040.01115.53
7.0.160.0000.01215.20
7.0.150.0070.00715.25
7.0.140.0060.03918.70
7.0.130.0070.00315.56
7.0.120.0050.00515.52
7.0.110.0090.00615.57
7.0.100.0200.03517.65
7.0.90.0180.04517.79
7.0.80.0080.04517.72
7.0.70.0100.02717.75
7.0.60.0080.03217.57
7.0.50.0170.03817.79
7.0.40.0070.04416.72
7.0.30.0050.02216.62
7.0.20.0070.01816.81
7.0.10.0070.02116.83
7.0.00.0070.04216.64
5.6.400.0130.00714.30
5.6.390.0060.00614.18
5.6.380.0000.00914.38
5.6.370.0060.00614.05
5.6.360.0130.00314.45
5.6.350.0060.00914.37
5.6.340.0040.00814.73
5.6.330.0030.00814.84
5.6.320.0030.01314.66
5.6.310.0030.01014.50
5.6.300.0060.00614.66
5.6.290.0070.01014.60
5.6.280.0050.03817.76
5.6.270.0000.01514.34
5.6.260.0030.00914.79
5.6.250.0070.04317.40
5.6.240.0090.03017.64
5.6.230.0070.03717.46
5.6.220.0140.03917.46
5.6.210.0060.03217.53
5.6.200.0030.04817.65
5.6.190.0050.03517.72
5.6.180.0020.02717.59
5.6.170.0110.04117.79
5.6.160.0070.04517.74
5.6.150.0070.04917.80
5.6.140.0050.02517.80
5.6.130.0050.02617.61
5.6.120.0100.03917.75
5.6.110.0090.04017.87
5.6.100.0070.02017.63
5.6.90.0060.04517.79
5.6.80.0070.03817.49
5.6.70.0030.02417.54
5.6.60.0060.03017.27
5.6.50.0010.02717.46
5.6.40.0050.02517.28
5.6.30.0070.04117.39
5.6.20.0050.02017.59
5.6.10.0030.02517.36
5.6.00.0080.02517.44
5.5.380.0020.03017.50
5.5.370.0120.04317.52
5.5.360.0090.03017.42
5.5.350.0080.01817.50
5.5.340.0120.02317.41
5.5.330.0030.03317.59
5.5.320.0100.04117.71
5.5.310.0070.04417.59
5.5.300.0050.02317.60
5.5.290.0060.02617.81
5.5.280.0090.02017.63
5.5.270.0080.04717.54
5.5.260.0090.04217.62
5.5.250.0020.02917.59
5.5.240.0020.03017.26
5.5.230.0050.04317.17
5.5.220.0020.02617.37
5.5.210.0050.02817.29
5.5.200.0050.02317.43
5.5.190.0120.04017.25
5.5.180.0090.03717.21
5.5.170.0110.00814.54
5.5.160.0090.04717.40
5.5.150.0040.03517.32
5.5.140.0110.03717.29
5.5.130.0050.04317.26
5.5.120.0030.04517.31
5.5.110.0110.04017.31
5.5.100.0120.02117.16
5.5.90.0100.03517.11
5.5.80.0080.02917.17
5.5.70.0080.04117.24
5.5.60.0060.02317.04
5.5.50.0070.04017.36
5.5.40.0030.04317.26
5.5.30.0080.02017.21
5.5.20.0030.02317.26
5.5.10.0050.03117.27
5.5.00.0040.03917.08
5.4.450.0090.02816.00
5.4.440.0020.02715.99
5.4.430.0020.03116.08
5.4.420.0080.02116.04
5.4.410.0080.01715.98
5.4.400.0060.04015.84
5.4.390.0050.03915.86
5.4.380.0060.04315.83
5.4.370.0090.02015.83
5.4.360.0020.02615.83
5.4.350.0080.01515.89
5.4.340.0030.02215.83
5.4.330.0150.00012.63
5.4.320.0060.04315.93
5.4.310.0080.03615.83
5.4.300.0060.04115.87
5.4.290.0070.04015.88
5.4.280.0050.02815.75
5.4.270.0120.03415.75
5.4.260.0050.03815.83
5.4.250.0080.01815.83
5.4.240.0070.04015.83
5.4.230.0020.02115.90
5.4.220.0080.04015.82
5.4.210.0030.02515.83
5.4.200.0070.01915.82
5.4.190.0020.02515.92
5.4.180.0060.01815.91
5.4.170.0060.03415.88
5.4.160.0020.02415.84
5.4.150.0070.02515.75
5.4.140.0000.02414.48
5.4.130.0060.02114.54
5.4.120.0080.03614.54
5.4.110.0090.03014.55
5.4.100.0030.02814.50
5.4.90.0080.03514.60
5.4.80.0050.03314.59
5.4.70.0080.03814.52
5.4.60.0060.02814.51
5.4.50.0070.04014.52
5.4.40.0050.03514.52
5.4.30.0050.02714.49
5.4.20.0090.03014.55
5.4.10.0060.03514.55
5.4.00.0050.03414.20
5.3.290.0070.03813.66
5.3.280.0070.02113.63
5.3.270.0030.04713.63
5.3.260.0030.03813.67
5.3.250.0050.03813.60
5.3.240.0070.04113.66
5.3.230.0050.03513.64
5.3.220.0070.03213.65
5.3.210.0070.03413.61
5.3.200.0060.02013.65
5.3.190.0020.04213.57
5.3.180.0030.03313.61
5.3.170.0050.01913.66
5.3.160.0030.02113.64
5.3.150.0070.03613.65
5.3.140.0020.04513.63
5.3.130.0050.03913.62
5.3.120.0090.03613.65
5.3.110.0040.03113.59
5.3.100.0050.04013.34
5.3.90.0020.03813.38
5.3.80.0020.03113.34
5.3.70.0050.03513.35
5.3.60.0100.01813.35
5.3.50.0040.04113.28
5.3.40.0060.04013.29
5.3.30.0080.03813.24
5.3.20.0110.01813.19
5.3.10.0050.03513.18
5.3.00.0030.04213.13
5.2.170.0030.03311.16
5.2.160.0030.05711.27
5.2.150.0100.04711.11
5.2.140.0030.05711.11
5.2.130.0070.05711.20
5.2.120.0030.05311.25
5.2.110.0030.05311.11
5.2.100.0030.05711.20
5.2.90.0030.03311.20
5.2.80.0100.05311.11
5.2.70.0070.05011.20
5.2.60.0030.02711.12
5.2.50.0000.03011.13
5.2.40.0000.03311.12
5.2.30.0070.05711.11
5.2.20.0030.06011.11
5.2.10.0100.05311.11
5.2.00.0070.05011.11
5.1.60.0000.03011.11
5.1.50.0030.03011.11
5.1.40.0000.04311.11
5.1.30.0070.05311.11
5.1.20.0070.05011.11
5.1.10.0030.05711.11
5.1.00.0070.02011.11
5.0.50.0070.04011.11
5.0.40.0000.01711.11
5.0.30.0030.06311.11
5.0.20.0030.01711.11
5.0.10.0030.01711.11
5.0.00.0000.06711.11
4.4.90.0030.03711.11
4.4.80.0070.02011.11
4.4.70.0000.03711.11
4.4.60.0030.04011.11
4.4.50.0000.02711.11
4.4.40.0030.03011.11
4.4.30.0030.01311.11
4.4.20.0000.03311.11
4.4.10.0000.03011.11
4.4.00.0000.02711.11
4.3.110.0000.02311.11
4.3.100.0070.01311.11
4.3.90.0000.03011.11
4.3.80.0000.05311.11
4.3.70.0000.01711.11
4.3.60.0000.01311.11
4.3.50.0030.01311.11
4.3.40.0070.04711.11
4.3.30.0000.03011.11
4.3.20.0000.03311.11
4.3.10.0030.01311.11
4.3.00.0000.02011.11

preferences:
34.78 ms | 401 KiB | 5 Q