3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen() { $data = array(); $i = 0; for($i; $i < 50; $i++) { $data[$i] = array( 'indent' => 'test ' . $i, 'depth' => 1 ); } return array(); } echo serialize(gen()); /* $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, ) ); */ $array = unserialize('a:0:{}'); /* 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.0060.01818.43
8.3.50.0150.00522.17
8.3.40.0080.01218.69
8.3.30.0100.00318.74
8.3.20.0080.00018.74
8.3.10.0080.00021.05
8.3.00.0060.00618.88
8.2.180.0150.00618.41
8.2.170.0060.00922.96
8.2.160.0160.00620.39
8.2.150.0050.00324.18
8.2.140.0050.00324.66
8.2.130.0000.00826.16
8.2.120.0030.00521.05
8.2.110.0070.00320.30
8.2.100.0050.00517.91
8.2.90.0080.00019.29
8.2.80.0040.00417.97
8.2.70.0060.00317.50
8.2.60.0080.00017.93
8.2.50.0030.00618.07
8.2.40.0040.00418.29
8.2.30.0030.00319.47
8.2.20.0080.00017.71
8.2.10.0050.00217.78
8.2.00.0060.00317.78
8.1.280.0070.01325.92
8.1.270.0070.00023.99
8.1.260.0070.00026.35
8.1.250.0070.00028.09
8.1.240.0060.00322.45
8.1.230.0110.00021.03
8.1.220.0040.00418.77
8.1.210.0040.00418.91
8.1.200.0040.00417.35
8.1.190.0000.00817.43
8.1.180.0030.00618.10
8.1.170.0000.00918.53
8.1.160.0000.00718.76
8.1.150.0000.00718.63
8.1.140.0040.00417.45
8.1.130.0030.00317.74
8.1.120.0040.00417.32
8.1.110.0040.00417.31
8.1.100.0040.00417.42
8.1.90.0040.00417.29
8.1.80.0070.00017.37
8.1.70.0000.00717.38
8.1.60.0030.00617.59
8.1.50.0000.00817.37
8.1.40.0050.00317.51
8.1.30.0000.00817.67
8.1.20.0040.00417.67
8.1.10.0030.00617.54
8.1.00.0040.00417.39
8.0.300.0050.00319.94
8.0.290.0000.00917.04
8.0.280.0030.00318.39
8.0.270.0030.00317.13
8.0.260.0030.00316.88
8.0.250.0000.00716.88
8.0.240.0040.00417.02
8.0.230.0030.00416.92
8.0.220.0030.00316.97
8.0.210.0030.00316.89
8.0.200.0060.00017.07
8.0.190.0000.00817.00
8.0.180.0000.00716.86
8.0.170.0000.00816.94
8.0.160.0070.00016.84
8.0.150.0030.00316.80
8.0.140.0000.00816.81
8.0.130.0080.00013.34
8.0.120.0050.00316.89
8.0.110.0030.00516.81
8.0.100.0040.00416.80
8.0.90.0070.00016.93
8.0.80.0070.01016.98
8.0.70.0000.00816.75
8.0.60.0040.00416.86
8.0.50.0070.00016.70
8.0.30.0110.01117.17
8.0.20.0230.01417.40
8.0.10.0000.00816.88
8.0.00.0100.01116.71
7.4.330.0000.00516.88
7.4.320.0060.00016.46
7.4.300.0030.00316.50
7.4.290.0030.00316.48
7.4.280.0070.00016.52
7.4.270.0050.00216.52
7.4.260.0000.00513.38
7.4.250.0080.00016.44
7.4.240.0030.00516.55
7.4.230.0050.00316.39
7.4.220.0030.01516.45
7.4.210.0110.00416.56
7.4.200.0030.00316.63
7.4.190.0000.00716.64
7.4.160.0040.01816.56
7.4.150.0090.00917.40
7.4.140.0110.00617.86
7.4.130.0080.01216.53
7.4.120.0090.00816.50
7.4.110.0100.00616.59
7.4.100.0120.00916.42
7.4.90.0070.01116.55
7.4.80.0120.00619.39
7.4.70.0060.01616.40
7.4.60.0040.01416.54
7.4.50.0090.00016.19
7.4.40.0200.00022.77
7.4.30.0130.00316.38
7.4.00.0110.00714.93
7.3.330.0000.00713.37
7.3.320.0000.00513.18
7.3.310.0000.00716.45
7.3.300.0000.00716.20
7.3.290.0090.00916.34
7.3.280.0110.00916.38
7.3.270.0150.00917.40
7.3.260.0130.00718.24
7.3.250.0080.00816.53
7.3.240.0100.00616.34
7.3.230.0100.01016.45
7.3.210.0100.01016.44
7.3.200.0110.01019.39
7.3.190.0120.00916.49
7.3.180.0110.00416.41
7.3.170.0110.01116.45
7.3.160.0100.00716.55
7.3.120.0060.00814.99
7.3.110.0040.01214.91
7.3.100.0070.01115.00
7.3.90.0060.01215.06
7.3.80.0060.00614.61
7.3.70.0070.01014.82
7.3.60.0080.00514.75
7.3.50.0090.00614.61
7.3.40.0070.00714.72
7.3.30.0060.00314.73
7.3.20.0090.00616.70
7.3.10.0110.00316.60
7.3.00.0080.01116.63
7.2.330.0060.01116.71
7.2.320.0070.01016.82
7.2.310.0110.01116.50
7.2.300.0130.00716.60
7.2.290.0030.01316.85
7.2.250.0140.00415.02
7.2.240.0070.01114.68
7.2.230.0110.00715.28
7.2.220.0060.01214.92
7.2.210.0100.00715.06
7.2.200.0090.00615.05
7.2.190.0070.00715.13
7.2.180.0120.00314.96
7.2.170.0030.01415.13
7.2.130.0000.01816.63
7.2.120.0230.00616.81
7.2.110.0060.00916.68
7.2.100.0130.00816.68
7.2.90.0140.00016.67
7.2.80.0080.01016.73
7.2.70.0040.01116.84
7.2.60.0080.00416.47
7.2.50.0030.00916.66
7.2.40.0050.00516.72
7.2.30.0000.01416.92
7.2.20.0030.00616.50
7.2.10.0030.00616.39
7.2.00.0080.00518.00
7.1.330.0070.01015.99
7.1.320.0030.01015.87
7.1.310.0070.00715.92
7.1.300.0080.00415.70
7.1.290.0000.01715.92
7.1.280.0070.00315.97
7.1.270.0030.00515.52
7.1.260.0070.00715.86
7.1.250.0180.00415.32
7.1.100.0070.00717.96
7.1.70.0030.01017.37
7.1.60.0080.00317.08
7.1.50.0070.01416.93
7.1.00.0070.03022.30
7.0.200.0070.00716.59
7.0.140.0000.07722.21
7.0.60.0130.07721.75
7.0.50.0130.07717.90
7.0.40.0100.04020.21
7.0.30.0330.04020.11
7.0.20.0300.07720.10
7.0.10.0030.04320.30
7.0.00.0000.04320.25
5.6.280.0070.07021.12
5.6.210.0100.07020.54
5.6.200.0000.05018.29
5.6.190.0030.09320.55
5.6.180.0330.07020.42
5.6.170.0200.07320.45
5.6.160.0070.08020.62
5.6.150.0130.07318.18
5.6.140.0130.06018.28
5.6.130.0030.04018.25
5.6.120.0070.05721.04
5.6.110.0100.05321.00
5.6.100.0100.08021.11
5.6.90.0070.08320.97
5.6.80.0100.06320.52
5.5.350.3300.04020.45
5.5.340.0000.04718.05
5.5.330.0030.09020.27
5.5.320.0070.06020.33
5.5.310.0300.04720.36
5.5.300.0230.06318.05
5.5.290.0030.09017.97
5.5.280.0130.06720.90
5.5.270.0130.06720.87
5.5.260.0170.07720.73
5.5.250.0070.06320.76
5.5.240.0230.07020.26
5.4.450.3830.04019.41
5.4.440.3770.03719.48
5.4.430.3730.04319.38
5.4.420.3630.03719.54
5.4.410.3830.03719.14
5.4.400.3400.03019.00
5.4.390.4870.03719.13
5.4.380.3730.03719.16
5.4.370.3700.03719.09
5.4.360.3570.03319.15
5.4.350.3800.04019.32
5.4.340.3570.04019.05
5.4.320.3570.04319.16
5.4.310.3630.03719.31
5.4.300.3630.03019.20
5.4.290.3670.03719.01
5.4.280.3530.04018.85
5.4.270.4070.04319.24
5.4.260.3900.03718.85
5.4.250.2970.04319.22
5.4.240.4130.04318.98
5.4.230.3470.04319.21
5.4.220.3770.04319.12
5.4.210.3800.03719.23
5.4.200.3830.03018.98
5.4.190.3800.03718.97
5.4.180.3800.03719.15
5.4.170.3500.03718.84
5.4.160.3770.03719.13
5.4.150.3870.03718.96
5.4.140.3800.04016.48
5.4.130.3600.03016.36
5.4.120.3600.03716.35
5.4.110.3330.04016.35
5.4.100.3500.03716.46
5.4.90.3900.03316.57
5.4.80.3800.03716.49
5.4.70.3670.02716.29
5.4.60.3270.03716.19
5.4.50.3600.03016.45
5.4.40.3900.04016.33
5.4.30.3600.04016.44
5.4.20.3900.03316.52
5.4.10.3570.03316.48
5.4.00.4130.03315.80
5.3.290.3370.03714.74
5.3.280.3970.03014.67
5.3.270.4100.04314.71
5.3.260.3570.04014.62
5.3.250.4000.04014.55
5.3.240.3600.03314.61
5.3.230.3930.03714.84
5.3.220.3870.03714.58
5.3.210.4100.04314.50
5.3.200.3400.05014.56
5.3.190.3670.03314.56
5.3.180.4270.03714.56
5.3.170.3730.03314.75
5.3.160.3900.03714.60
5.3.150.3630.03314.50
5.3.140.3770.03714.66
5.3.130.3900.03314.57
5.3.120.3570.03714.58
5.3.110.3870.04014.48
5.3.100.3970.03314.14
5.3.90.4070.03714.01
5.3.80.4170.04314.13
5.3.70.3800.03314.16
5.3.60.3730.04014.10
5.3.50.3970.03313.88
5.3.40.3630.04013.95
5.3.30.3630.03713.84
5.3.20.3600.04013.69
5.3.10.3830.03713.62
5.3.00.3600.03013.57
5.2.170.3500.02711.15
5.2.160.3230.02711.25
5.2.150.3230.03311.15
5.2.140.3330.03311.39
5.2.130.3000.02711.11
5.2.120.3300.02311.03
5.2.110.2830.02311.13
5.2.100.3000.02311.35
5.2.90.3170.03011.18
5.2.80.3270.02711.30
5.2.70.2930.03011.03
5.2.60.4100.02711.15
5.2.50.2870.02711.15
5.2.40.2430.02311.02
5.2.30.2600.02711.02
5.2.20.2570.02711.06
5.2.10.2470.02711.02
5.2.00.2700.03711.02
5.1.60.2630.02711.02
5.1.50.2430.02711.02
5.1.40.2600.02711.02
5.1.30.2630.02711.02
5.1.20.2630.02711.02
5.1.10.2370.03011.02
5.1.00.2500.02011.02
5.0.50.1500.01711.02
5.0.40.1230.01711.02
5.0.30.1400.03311.02
5.0.20.1270.02011.02
5.0.10.1370.02011.02
5.0.00.1230.03311.02
4.4.90.1270.01311.02
4.4.80.1400.01711.02
4.4.70.1130.01711.02
4.4.60.1330.01711.02
4.4.50.1400.02011.02
4.4.40.1470.03011.02
4.4.30.1370.02011.02
4.4.20.1300.01311.02
4.4.10.1370.02011.02
4.4.00.1200.02711.02
4.3.110.1330.02011.02
4.3.100.1500.01311.02
4.3.90.1100.01311.02
4.3.80.1200.02311.02
4.3.70.1270.01711.02
4.3.60.1370.01311.02
4.3.50.1500.01711.02
4.3.40.1330.02311.02
4.3.30.0700.01711.02
4.3.20.0770.02311.02
4.3.10.0770.02711.02
4.3.00.0770.01711.02

preferences:
47.62 ms | 401 KiB | 5 Q