3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen() { $data = array(); 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, ) ); 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.0160.00318.30
8.3.50.0090.01022.11
8.3.40.0070.01418.77
8.3.30.0040.01118.59
8.3.20.0080.00018.74
8.3.10.0040.00421.09
8.3.00.0060.00320.69
8.2.180.0100.00716.50
8.2.170.0070.01122.96
8.2.160.0000.01320.57
8.2.150.0080.00024.18
8.2.140.0030.00524.66
8.2.130.0060.00326.16
8.2.120.0040.00421.13
8.2.110.0030.00620.35
8.2.100.0090.00317.91
8.2.90.0030.00619.21
8.2.80.0040.00419.25
8.2.70.0060.00317.63
8.2.60.0000.00918.03
8.2.50.0040.00818.07
8.2.40.0080.00018.22
8.2.30.0070.00019.52
8.2.20.0000.00717.72
8.2.10.0070.00017.51
8.2.00.0090.00017.63
8.1.280.0150.00025.92
8.1.270.0040.00423.99
8.1.260.0080.00026.35
8.1.250.0000.00828.09
8.1.240.0030.00622.45
8.1.230.0090.00320.85
8.1.220.0050.00318.77
8.1.210.0000.00818.91
8.1.200.0030.00617.23
8.1.190.0000.00817.51
8.1.180.0050.00318.10
8.1.170.0090.00018.43
8.1.160.0080.00018.88
8.1.150.0040.00418.61
8.1.140.0040.00417.30
8.1.130.0000.00817.71
8.1.120.0000.00717.32
8.1.110.0040.00417.37
8.1.100.0040.00417.32
8.1.90.0050.00317.38
8.1.80.0080.00017.39
8.1.70.0070.00017.37
8.1.60.0060.00317.64
8.1.50.0040.00417.47
8.1.40.0070.00017.50
8.1.30.0040.00417.67
8.1.20.0030.00517.57
8.1.10.0030.00717.52
8.1.00.0040.00417.50
8.0.300.0040.00419.89
8.0.290.0000.00717.04
8.0.280.0000.00718.44
8.0.270.0040.00417.29
8.0.260.0000.00616.84
8.0.250.0040.00416.95
8.0.240.0000.00816.85
8.0.230.0040.00416.81
8.0.220.0030.00316.75
8.0.210.0000.00716.80
8.0.200.0070.00016.86
8.0.190.0000.00916.79
8.0.180.0080.00016.71
8.0.170.0060.00316.84
8.0.160.0030.00316.78
8.0.150.0000.00716.70
8.0.140.0000.00816.77
8.0.130.0070.00013.16
8.0.120.0000.00816.70
8.0.110.0030.00416.80
8.0.100.0000.00716.70
8.0.90.0040.00416.80
8.0.80.0060.00916.80
8.0.70.0040.00416.81
8.0.60.0000.00716.90
8.0.50.0050.00216.77
8.0.30.0080.01016.85
8.0.20.0210.02217.40
8.0.10.0000.00716.77
8.0.00.0040.01316.83
7.4.330.0000.00516.84
7.4.320.0020.00516.32
7.4.300.0030.00316.54
7.4.290.0000.00716.65
7.4.280.0000.00716.53
7.4.270.0000.00616.60
7.4.260.0060.00013.29
7.4.250.0030.00516.47
7.4.240.0000.00716.49
7.4.230.0050.00216.59
7.4.220.0090.00916.67
7.4.210.0050.01116.61
7.4.200.0070.00016.59
7.4.190.0070.00016.56
7.4.160.0030.01216.57
7.4.150.0120.00617.40
7.4.140.0030.01617.86
7.4.130.0120.00516.45
7.4.120.0100.00616.54
7.4.110.0100.00616.51
7.4.100.0100.00716.72
7.4.90.0030.01516.43
7.4.80.0100.00719.39
7.4.70.0130.00716.50
7.4.60.0060.01016.57
7.4.50.0040.00416.40
7.4.40.0060.01022.77
7.4.30.0090.00916.54
7.4.00.0000.01814.84
7.3.330.0070.00013.23
7.3.320.0060.00013.21
7.3.310.0030.00316.26
7.3.300.0000.00716.23
7.3.290.0100.00316.20
7.3.280.0090.00816.18
7.3.270.0160.00617.40
7.3.260.0140.00918.24
7.3.250.0050.01216.64
7.3.240.0070.01016.36
7.3.230.0030.01316.46
7.3.210.0030.01316.42
7.3.200.0060.01019.39
7.3.190.0060.01116.27
7.3.180.0090.00616.42
7.3.170.0060.00916.27
7.3.160.0130.00316.39
7.3.120.0000.01614.73
7.2.330.0130.00316.61
7.2.320.0030.01516.60
7.2.310.0120.00616.21
7.2.300.0130.00316.30
7.2.290.0000.01616.59
7.2.60.0030.01316.88
7.2.00.0030.00919.13
7.1.200.0030.00915.40
7.1.100.0070.01017.96
7.1.70.0000.00717.10
7.1.60.0070.00416.89
7.1.50.0070.01416.81
7.1.00.0000.05022.30
7.0.200.0040.01116.75
7.0.140.0000.07322.10
7.0.100.0370.07319.92
7.0.90.0170.08719.91
7.0.80.0130.08019.89
7.0.70.0130.08319.87
7.0.60.0130.06720.03
7.0.50.0130.05720.35
7.0.40.0100.05720.07
7.0.30.0100.08020.10
7.0.20.0170.08020.04
7.0.10.0100.05020.10
7.0.00.0100.07020.13
5.6.280.0000.07721.13
5.6.250.0170.07020.57
5.6.240.0200.08020.61
5.6.230.0130.04720.64
5.6.220.0070.08320.62
5.6.210.0030.08720.67
5.6.200.0130.07721.13
5.6.190.0200.04021.14
5.6.180.0070.08321.08
5.6.170.0030.09321.14
5.6.160.0100.08020.95
5.6.150.0100.06721.02
5.6.140.0100.06321.02
5.6.130.0170.07721.01
5.6.120.0030.07721.10
5.6.110.0070.07721.05
5.6.100.0070.08020.91
5.6.90.0070.08021.04
5.6.80.0070.06020.56
5.6.70.0100.08020.33
5.6.60.0130.07320.31
5.6.50.0170.07320.50
5.6.40.0070.07720.30
5.6.30.0100.06320.40
5.6.20.0100.07320.38
5.6.10.0030.07720.29
5.6.00.0100.07320.31
5.5.380.0170.08020.54
5.5.370.0170.06320.38
5.5.360.0070.08320.35
5.5.350.0070.08020.44
5.5.340.0070.08020.93
5.5.330.0100.06320.89
5.5.320.0130.07720.91
5.5.310.0070.08720.64
5.5.300.0070.08020.89
5.5.290.0070.07720.73
5.5.280.0130.04320.90
5.5.270.0100.08320.83
5.5.260.0130.08020.86
5.5.250.0100.08020.70
5.5.240.0100.07720.22
5.5.230.0100.08320.21
5.5.220.0070.07720.24
5.5.210.0130.07320.24
5.5.200.0030.06320.12
5.5.190.0200.06720.18
5.5.180.0170.07319.99
5.5.160.0030.08320.28
5.5.150.0200.06020.24
5.5.140.0100.05720.27
5.5.130.0030.08720.18
5.5.120.0030.05020.26
5.5.110.0030.05020.27
5.5.100.0130.07720.14
5.5.90.0070.07320.16
5.5.80.0100.04320.04
5.5.70.0070.08020.04
5.5.60.0100.04020.09
5.5.50.0030.08320.09
5.5.40.0170.08019.98
5.5.30.0170.05320.01
5.5.20.0100.07319.96
5.5.10.0000.07320.03
5.5.00.0070.07720.12
5.4.450.0030.04319.21
5.4.440.0130.06319.20
5.4.430.0170.07019.41
5.4.420.0170.07019.20
5.4.410.0000.09019.43
5.4.400.0070.06719.16
5.4.390.0070.07719.14
5.4.380.0030.08319.13
5.4.370.0170.07018.88
5.4.360.0170.07319.04
5.4.350.0070.04318.88
5.4.340.0100.06719.14
5.4.320.0000.07319.04
5.4.310.0070.03719.14
5.4.300.0070.07719.21
5.4.290.0100.08018.90
5.4.280.0030.08019.05
5.4.270.0070.07319.18
5.4.260.0100.07718.96
5.4.250.0100.07318.86
5.4.240.0070.07719.21
5.4.230.0070.08319.19
5.4.220.0030.06018.84
5.4.210.0130.07018.90
5.4.200.0070.06019.20
5.4.190.0070.08019.13
5.4.180.0100.04718.84
5.4.170.0130.07018.89
5.4.160.0070.07718.82
5.4.150.0000.08318.83
5.4.140.0170.06716.41
5.4.130.0070.03316.29
5.4.120.0200.06016.40
5.4.110.0070.07716.37
5.4.100.0070.06716.50
5.4.90.0100.08016.39
5.4.80.0070.03316.38
5.4.70.0130.06316.26
5.4.60.0100.04016.41
5.4.50.0100.06716.39
5.4.40.0170.06016.46
5.4.30.0100.06716.37
5.4.20.0070.07316.32
5.4.10.0030.07316.40
5.4.00.0030.08015.86
5.3.290.0070.07014.80
5.3.280.0100.08014.65
5.3.270.0070.08314.66
5.3.260.0030.07014.58
5.3.250.0100.07014.72
5.3.240.0070.07014.66
5.3.230.0130.07314.55
5.3.220.0070.06314.49
5.3.210.0000.05014.60
5.3.200.0130.08014.64
5.3.190.0100.07314.55
5.3.180.0030.07314.66
5.3.170.0070.07314.59
5.3.160.0000.07714.50
5.3.150.0100.04014.62
5.3.140.0070.05714.50
5.3.130.0130.06714.53
5.3.120.0100.05714.60
5.3.110.0030.07714.48
5.3.100.0030.06713.96
5.3.90.0170.04014.00
5.3.80.0170.06314.13
5.3.70.0070.07314.15
5.3.60.0070.06014.14
5.3.50.0100.06713.83
5.3.40.0030.05713.97
5.3.30.0030.05313.79
5.3.20.0030.06313.75
5.3.10.0100.06013.66
5.3.00.0100.06713.68
5.2.170.0070.06311.47
5.2.160.0070.05711.47
5.2.150.0030.06011.47
5.2.140.0000.04011.47
5.2.130.0000.06011.47
5.2.120.0000.06011.47
5.2.110.0030.05711.47
5.2.100.0030.05711.47
5.2.90.0030.06311.47
5.2.80.0070.05711.47
5.2.70.0030.06311.47
5.2.60.0030.06711.47
5.2.50.0100.02711.47
5.2.40.0070.05311.47
5.2.30.0070.05711.47
5.2.20.0030.06011.47
5.2.10.0100.05011.47
5.2.00.0070.06011.47
5.1.60.0070.02711.47
5.1.50.0070.02011.47
5.1.40.0070.03311.47
5.1.30.0030.03011.47
5.1.20.0030.03011.47
5.1.10.0000.03311.47
5.1.00.0000.03311.47
5.0.50.0000.02311.47
5.0.40.0000.02011.47
5.0.30.0030.02711.47
5.0.20.0000.02011.47
5.0.10.0030.04311.47
5.0.00.0000.04011.47
4.4.90.0030.02311.47
4.4.80.0030.02011.47
4.4.70.0070.03311.47
4.4.60.0000.03711.47
4.4.50.0030.02711.47
4.4.40.0000.04711.47
4.4.30.0000.02311.47
4.4.20.0070.01011.47
4.4.10.0000.01711.47
4.4.00.0030.02311.47
4.3.110.0070.01011.47
4.3.100.0000.01711.47
4.3.90.0070.03011.47
4.3.80.0070.01711.47
4.3.70.0030.01311.47
4.3.60.0000.02011.47
4.3.50.0030.01311.47
4.3.40.0000.02711.47
4.3.30.0000.01711.47
4.3.20.0000.01711.47
4.3.10.0030.02711.47
4.3.00.0000.02011.47

preferences:
44.2 ms | 401 KiB | 5 Q