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 $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.70.0150.00018.68
8.3.60.0040.01118.56
8.3.50.0080.00822.18
8.3.40.0070.01118.88
8.3.30.0080.00618.55
8.3.20.0050.00318.85
8.3.10.0080.00021.17
8.3.00.0100.00020.68
8.2.180.0100.01018.29
8.2.170.0080.00818.96
8.2.160.0000.01422.96
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00420.97
8.2.110.0060.00319.33
8.2.100.0080.00418.03
8.2.90.0030.00619.17
8.2.80.0000.00817.97
8.2.70.0080.00617.25
8.2.60.0050.00318.04
8.2.50.0090.00018.07
8.2.40.0000.00818.22
8.2.30.0050.00321.21
8.2.20.0030.00617.75
8.2.10.0050.00317.80
8.2.00.0080.00017.74
8.1.280.0100.01025.92
8.1.270.0040.00423.99
8.1.260.0090.00026.35
8.1.250.0070.00028.09
8.1.240.0060.00322.73
8.1.230.0080.00420.93
8.1.220.0030.00618.77
8.1.210.0000.00818.98
8.1.200.0070.00317.36
8.1.190.0050.00317.52
8.1.180.0050.00318.10
8.1.170.0040.00418.59
8.1.160.0070.00018.92
8.1.150.0000.00818.57
8.1.140.0030.00617.48
8.1.130.0030.00317.86
8.1.120.0050.00317.39
8.1.110.0080.00017.48
8.1.100.0030.00617.50
8.1.90.0080.00017.50
8.1.80.0000.00817.39
8.1.70.0030.00317.49
8.1.60.0040.00417.46
8.1.50.0030.00517.48
8.1.40.0040.00417.53
8.1.30.0060.00317.65
8.1.20.0030.00517.68
8.1.10.0030.00817.51
8.1.00.0030.00517.45
8.0.300.0000.00719.89
8.0.290.0050.00317.18
8.0.280.0000.00718.39
8.0.270.0070.00017.20
8.0.260.0030.00316.77
8.0.250.0050.00316.96
8.0.240.0050.00217.01
8.0.230.0000.00717.02
8.0.220.0000.00716.88
8.0.210.0070.00016.85
8.0.200.0070.00017.00
8.0.190.0000.00916.83
8.0.180.0050.00216.98
8.0.170.0050.00316.85
8.0.160.0030.00516.93
8.0.150.0040.00416.76
8.0.140.0040.00416.88
8.0.130.0030.00513.27
8.0.120.0000.00716.91
8.0.110.0030.00516.91
8.0.100.0000.00716.79
8.0.90.0000.00716.93
8.0.80.0030.01716.91
8.0.70.0040.00416.95
8.0.60.0040.00416.71
8.0.50.0000.00817.03
8.0.30.0060.01317.17
8.0.20.0150.00817.40
8.0.10.0040.00416.93
8.0.00.0090.01216.92
7.4.330.0020.00216.67
7.4.320.0060.00016.54
7.4.300.0030.00316.55
7.4.290.0000.00716.65
7.4.280.0070.00016.39
7.4.270.0070.00016.64
7.4.260.0000.00513.29
7.4.250.0090.00016.48
7.4.240.0040.00416.64
7.4.230.0030.00316.45
7.4.220.0090.01016.55
7.4.210.0070.00916.65
7.4.200.0040.00416.73
7.4.190.0030.00316.44
7.4.160.0060.01216.36
7.4.150.0030.01517.40
7.4.140.0190.01017.86
7.4.130.0110.00916.49
7.4.120.0110.00816.46
7.4.110.0070.01016.64
7.4.100.0180.00316.56
7.4.90.0140.00916.48
7.4.80.0030.01319.39
7.4.70.0120.00616.71
7.4.60.0070.01016.53
7.4.50.0000.00816.64
7.4.40.0000.01822.77
7.4.30.0120.00816.56
7.4.10.0070.00714.58
7.4.00.0080.00914.87
7.3.330.0070.00013.15
7.3.320.0030.00313.14
7.3.310.0000.00716.41
7.3.300.0030.00316.38
7.3.290.0030.01016.39
7.3.280.0080.00916.37
7.3.270.0130.01317.40
7.3.260.0110.00918.24
7.3.250.0080.00916.56
7.3.240.0120.00616.59
7.3.230.0060.01216.48
7.3.210.0060.01216.38
7.3.200.0090.00919.39
7.3.190.0090.00916.67
7.3.180.0070.00716.37
7.3.170.0070.01016.49
7.3.160.0090.00616.58
7.3.130.0070.01114.54
7.3.120.0070.01114.87
7.3.110.0060.01314.83
7.3.100.0060.00814.73
7.3.90.0060.00614.61
7.3.80.0060.00914.83
7.3.70.0070.00614.83
7.3.60.0070.00714.68
7.3.50.0040.01014.68
7.3.40.0070.00714.85
7.3.30.0080.00514.82
7.3.20.0050.00816.82
7.3.10.0070.00816.64
7.3.00.0070.00716.65
7.2.330.0160.00816.44
7.2.320.0130.00316.65
7.2.310.0040.01416.79
7.2.300.0070.01016.48
7.2.290.0100.00716.61
7.2.260.0100.01014.86
7.2.250.0110.00715.06
7.2.240.0070.01015.13
7.2.230.0070.00914.95
7.2.220.0020.01415.19
7.2.210.0060.00815.19
7.2.200.0050.00915.00
7.2.190.0060.00815.02
7.2.180.0070.01015.01
7.2.170.0080.00614.95
7.2.160.0120.00415.17
7.2.150.0060.00616.68
7.2.140.0060.00616.80
7.2.130.0090.00616.83
7.2.120.0030.01017.07
7.2.110.0030.00616.91
7.2.100.0030.00716.88
7.2.90.0090.00616.77
7.2.80.0110.00716.96
7.2.70.0030.01017.11
7.2.60.0100.00616.88
7.2.50.0060.00916.62
7.2.40.0090.01216.76
7.2.30.0000.01416.50
7.2.20.0070.00716.70
7.2.10.0030.00616.55
7.2.00.0050.00918.22
7.1.330.0060.00715.81
7.1.320.0080.01015.85
7.1.310.0090.00615.72
7.1.300.0050.01015.79
7.1.290.0060.00715.76
7.1.280.0040.00715.69
7.1.270.0050.00815.52
7.1.260.0040.00915.71
7.1.250.0050.00515.89
7.1.240.0070.00715.81
7.1.230.0070.00315.47
7.1.220.0070.00715.69
7.1.210.0070.00315.46
7.1.200.0060.00515.45
7.1.190.0070.00715.48
7.1.180.0150.00315.92
7.1.170.0090.00916.02
7.1.160.0040.00715.44
7.1.150.0030.00715.40
7.1.140.0100.00315.71
7.1.130.0090.00615.64
7.1.120.0030.00915.91
7.1.110.0100.00315.45
7.1.100.0050.01016.71
7.1.90.0070.00315.55
7.1.80.0030.00615.33
7.1.70.0070.00516.48
7.1.60.0040.00616.29
7.1.50.0060.00816.22
7.1.40.0030.00716.00
7.1.30.0030.00915.68
7.1.20.0030.00915.80
7.1.10.0000.01215.57
7.1.00.0040.02318.92
7.0.330.0000.00915.32
7.0.320.0060.00615.43
7.0.310.0000.00815.48
7.0.300.0030.00915.60
7.0.290.0100.00715.14
7.0.280.0030.00715.16
7.0.270.0030.00515.30
7.0.260.0040.01115.17
7.0.250.0040.01215.38
7.0.240.0120.00415.40
7.0.230.0030.01015.27
7.0.220.0090.00615.30
7.0.210.0060.00615.08
7.0.200.0070.00915.93
7.0.190.0040.00715.19
7.0.180.0040.01115.15
7.0.170.0040.00814.89
7.0.160.0050.00515.16
7.0.150.0110.00415.16
7.0.140.0100.02918.65
7.0.130.0040.00715.35
7.0.120.0100.00315.13
7.0.110.0000.01315.22
7.0.100.0180.03817.67
7.0.90.0270.03817.67
7.0.80.0210.04117.63
7.0.70.0120.03717.70
7.0.60.0090.02217.68
7.0.50.0120.03917.98
7.0.40.0070.04516.73
7.0.30.0050.04916.59
7.0.20.0030.04616.67
7.0.10.0090.04616.59
7.0.00.0030.03216.73
5.6.400.0070.00714.32
5.6.390.0060.00614.00
5.6.380.0060.00614.25
5.6.370.0040.00814.36
5.6.360.0040.00814.44
5.6.350.0000.01413.91
5.6.340.0070.00313.98
5.6.330.0080.00014.35
5.6.320.0030.01013.85
5.6.310.0060.00613.89
5.6.300.0120.00313.91
5.6.290.0070.00714.01
5.6.280.0100.03717.62
5.6.270.0030.01314.32
5.6.260.0120.00614.48
5.6.250.0100.02517.39
5.6.240.0060.04717.52
5.6.230.0050.04817.46
5.6.220.0030.02417.44
5.6.210.0120.04017.41
5.6.200.0090.04117.67
5.6.190.0030.04917.77
5.6.180.0050.04517.97
5.6.170.0040.03417.62
5.6.160.0050.04417.59
5.6.150.0060.04117.67
5.6.140.0070.02217.66
5.6.130.0050.04617.73
5.6.120.0090.04317.62
5.6.110.0100.04217.60
5.6.100.0080.02517.64
5.6.90.0070.04517.79
5.6.80.0050.02217.44
5.6.70.0050.04217.38
5.6.60.0100.03717.38
5.6.50.0110.04217.50
5.6.40.0020.04817.24
5.6.30.0050.03017.52
5.6.20.0070.04017.35
5.6.10.0130.03517.29
5.6.00.0020.05117.39
5.5.380.0100.04017.32
5.5.370.0110.04017.43
5.5.360.0050.02917.40
5.5.350.0060.04817.54
5.5.340.0070.04717.67
5.5.330.0140.04017.72
5.5.320.0050.04017.63
5.5.310.0090.04217.81
5.5.300.0030.02817.55
5.5.290.0120.04017.64
5.5.280.0080.04417.69
5.5.270.0080.04317.60
5.5.260.0100.04517.71
5.5.250.0060.04117.42
5.5.240.0070.04217.22
5.5.230.0080.02717.36
5.5.220.0070.04217.21
5.5.210.0030.04317.20
5.5.200.0080.04217.38
5.5.190.0020.05117.32
5.5.180.0120.03817.20
5.5.170.0040.00414.43
5.5.160.0100.04117.33
5.5.150.0070.04117.32
5.5.140.0110.04317.31
5.5.130.0070.03517.36
5.5.120.0060.03917.31
5.5.110.0100.03717.33
5.5.100.0080.04817.33
5.5.90.0090.04617.02
5.5.80.0070.04917.29
5.5.70.0040.04917.24
5.5.60.0080.03517.22
5.5.50.0130.03717.17
5.5.40.0120.02817.24
5.5.30.0070.04117.13
5.5.20.0060.04117.03
5.5.10.0030.04717.25
5.5.00.0070.02717.16
5.4.450.0050.04015.30
5.4.440.0120.03315.28
5.4.430.0070.04215.24
5.4.420.0070.04415.29
5.4.410.0070.03815.40
5.4.400.0000.04515.09
5.4.390.0030.02814.94
5.4.380.0020.03415.12
5.4.370.0050.04015.02
5.4.360.0000.04214.96
5.4.350.0040.04515.16
5.4.340.0070.04015.12
5.4.330.0040.00411.25
5.4.320.0060.03814.95
5.4.310.0060.04015.00
5.4.300.0030.04414.97
5.4.290.0090.04215.03
5.4.280.0030.03015.01
5.4.270.0080.03915.03
5.4.260.0040.04015.01
5.4.250.0070.02714.93
5.4.240.0090.03115.02
5.4.230.0060.04014.99
5.4.220.0120.03214.88
5.4.210.0090.04015.11
5.4.200.0090.03515.03
5.4.190.0050.03014.94
5.4.180.0100.04015.06
5.4.170.0050.03715.13
5.4.160.0050.03515.11
5.4.150.0070.04115.15
5.4.140.0070.04013.74
5.4.130.0100.03613.87
5.4.120.0070.03313.77
5.4.110.0110.03413.80
5.4.100.0050.04013.98
5.4.90.0060.03513.81
5.4.80.0080.04013.72
5.4.70.0060.03813.90
5.4.60.0050.04013.88
5.4.50.0100.03113.87
5.4.40.0080.03813.74
5.4.30.0060.03813.82
5.4.20.0080.03213.69
5.4.10.0070.03713.87
5.4.00.0020.04213.50
5.3.290.0050.02912.78
5.3.280.0030.04512.61
5.3.270.0110.03212.74
5.3.260.0090.03912.72
5.3.250.0030.04112.71
5.3.240.0090.03812.54
5.3.230.0000.04912.59
5.3.220.0030.03712.62
5.3.210.0130.03312.64
5.3.200.0050.03112.63
5.3.190.0080.04312.56
5.3.180.0050.03412.66
5.3.170.0040.04212.71
5.3.160.0020.04012.71
5.3.150.0070.03812.57
5.3.140.0100.02212.64
5.3.130.0050.03812.56
5.3.120.0020.04412.54
5.3.110.0080.03712.48
5.3.100.0040.02612.43
5.3.90.0100.03712.25
5.3.80.0050.04212.21
5.3.70.0070.03912.13
5.3.60.0060.03812.40
5.3.50.0030.04212.15
5.3.40.0070.03912.23
5.3.30.0030.02712.37
5.3.20.0090.03512.07
5.3.10.0080.02511.97
5.3.00.0050.02212.02
5.2.170.0030.06311.21
5.2.160.0070.06011.07
5.2.150.0000.07311.29
5.2.140.0070.06311.24
5.2.130.0030.04711.21
5.2.120.0070.06011.17
5.2.110.0030.03311.00
5.2.100.0000.03711.10
5.2.90.0030.05311.18
5.2.80.0030.06311.18
5.2.70.0170.05011.13
5.2.60.0030.05711.08
5.2.50.0000.06011.15
5.2.40.0100.05710.93
5.2.30.0030.06310.90
5.2.20.0030.04310.89
5.2.10.0070.05710.89
5.2.00.0100.04710.89
5.1.60.0070.05010.89
5.1.50.0000.02710.89
5.1.40.0030.05310.89
5.1.30.0070.04710.89
5.1.20.0030.04310.89
5.1.10.0070.02310.89
5.1.00.0100.05310.89
5.0.50.0030.02710.89
5.0.40.0000.05010.89
5.0.30.0000.04310.89
5.0.20.0030.02010.89
5.0.10.0000.02710.89
5.0.00.0000.05710.89
4.4.90.0030.02310.89
4.4.80.0000.02710.89
4.4.70.0130.02710.89
4.4.60.0030.03310.89
4.4.50.0000.03710.89
4.4.40.0100.03010.89
4.4.30.0000.03710.89
4.4.20.0000.04010.89
4.4.10.0030.03310.89
4.4.00.0000.05710.89
4.3.110.0030.03010.89
4.3.100.0030.01710.89
4.3.90.0000.02010.89
4.3.80.0000.05710.89
4.3.70.0070.03310.89
4.3.60.0000.03710.89
4.3.50.0000.03310.89
4.3.40.0000.03310.89
4.3.30.0030.01710.89
4.3.20.0000.03710.89
4.3.10.0000.02010.89
4.3.00.0100.02710.89

preferences:
48.45 ms | 401 KiB | 5 Q