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 &find_by_key($key, $array) { foreach($array as $k => &$v) { if($key == $k) { return $v; } } foreach($array as $sub) { if(isset($sub['children']) && FALSE !== ($found = find_by_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 { $parent = &find_by_key($sub['parent_id'], $out); var_dump($parent); $parent['children'][$key] = $sub; } } 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.00016.63
8.3.60.0080.00818.68
8.3.50.0110.00821.99
8.3.40.0110.00418.92
8.3.30.0150.00418.88
8.3.20.0090.00018.77
8.3.10.0080.00020.92
8.3.00.0060.00318.74
8.2.180.0120.00916.63
8.2.170.0040.01122.96
8.2.160.0030.01020.34
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0060.00326.16
8.2.120.0090.00621.21
8.2.110.0050.00521.02
8.2.100.0110.00018.03
8.2.90.0080.00019.18
8.2.80.0020.00519.26
8.2.70.0000.01017.75
8.2.60.0000.00817.93
8.2.50.0080.00018.07
8.2.40.0040.00417.91
8.2.30.0040.00421.09
8.2.20.0040.00417.63
8.2.10.0050.00317.91
8.2.00.0050.00317.85
8.1.280.0070.01025.92
8.1.270.0040.00423.99
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0090.00023.92
8.1.230.0140.00017.42
8.1.220.0030.00518.77
8.1.210.0000.00818.95
8.1.200.0060.00317.23
8.1.190.0000.00817.52
8.1.180.0040.00418.10
8.1.170.0000.00818.54
8.1.160.0050.00218.86
8.1.150.0000.00718.67
8.1.140.0040.00417.54
8.1.130.0000.00717.85
8.1.120.0040.00417.38
8.1.110.0040.00417.52
8.1.100.0030.00517.59
8.1.90.0040.00417.54
8.1.80.0000.00717.40
8.1.70.0000.00717.45
8.1.60.0090.00017.64
8.1.50.0040.00417.52
8.1.40.0090.00017.61
8.1.30.0050.00217.68
8.1.20.0000.00817.68
8.1.10.0000.00817.45
8.1.00.0030.00517.51
8.0.300.0000.00819.90
8.0.290.0040.00417.18
8.0.280.0050.00318.37
8.0.270.0030.00317.16
8.0.260.0070.00016.82
8.0.250.0040.00416.94
8.0.240.0040.00417.05
8.0.230.0070.00016.89
8.0.220.0000.00716.95
8.0.210.0050.00216.98
8.0.200.0000.00717.01
8.0.190.0000.00816.95
8.0.180.0090.00016.94
8.0.170.0050.00317.06
8.0.160.0040.00416.89
8.0.150.0040.00416.84
8.0.140.0050.00316.88
8.0.130.0000.00613.39
8.0.120.0000.00817.02
8.0.110.0030.00616.82
8.0.100.0040.00417.02
8.0.90.0040.00416.93
8.0.80.0160.00616.96
8.0.70.0000.00816.90
8.0.60.0040.00416.87
8.0.50.0070.00016.86
8.0.30.0100.01017.23
8.0.20.0110.01117.40
8.0.10.0070.00017.09
8.0.00.0110.01016.65
7.4.330.0000.00516.66
7.4.320.0030.00316.59
7.4.300.0030.00316.45
7.4.290.0030.00316.55
7.4.280.0040.00416.53
7.4.270.0030.00316.68
7.4.260.0030.00313.25
7.4.250.0030.00516.49
7.4.240.0000.00716.64
7.4.230.0030.00316.66
7.4.220.0030.01716.61
7.4.210.0060.01116.62
7.4.200.0050.00316.38
7.4.190.0000.00716.50
7.4.160.0060.01116.41
7.4.150.0090.00917.40
7.4.140.0110.00917.86
7.4.130.0110.00916.55
7.4.120.0110.00716.48
7.4.110.0100.00716.50
7.4.100.0090.01216.45
7.4.90.0120.00616.67
7.4.80.0150.01819.39
7.4.70.0150.00316.43
7.4.60.0120.00916.32
7.4.50.0000.00916.53
7.4.40.0090.00622.77
7.4.30.0090.00916.39
7.4.00.0120.00514.87
7.3.330.0040.00413.31
7.3.320.0060.00013.43
7.3.310.0030.00316.45
7.3.300.0000.00716.45
7.3.290.0030.01016.49
7.3.280.0060.01316.49
7.3.270.0080.01517.40
7.3.260.0090.01018.24
7.3.250.0080.00916.54
7.3.240.0080.00816.39
7.3.230.0120.00516.63
7.3.210.0100.00716.51
7.3.200.0040.01819.39
7.3.190.0140.00316.52
7.3.180.0030.01716.46
7.3.170.0110.00716.52
7.3.160.0100.00516.50
7.3.120.0060.00914.91
7.3.110.0000.01314.78
7.3.100.0060.00614.95
7.3.90.0000.01014.56
7.3.80.0000.01415.14
7.3.70.0070.00414.80
7.3.60.0060.01014.91
7.3.50.0120.00314.89
7.3.40.0070.00314.82
7.3.30.0040.00714.68
7.3.20.0070.00716.59
7.3.10.0100.00316.75
7.3.00.0100.00716.77
7.2.330.0080.01216.70
7.2.320.0060.01216.85
7.2.310.0060.01316.52
7.2.300.0050.01116.89
7.2.290.0110.00616.86
7.2.250.0040.01515.04
7.2.240.0030.01415.29
7.2.230.0060.00614.78
7.2.220.0060.00614.75
7.2.210.0040.01115.21
7.2.200.0040.00815.23
7.2.190.0060.01015.07
7.2.180.0030.01415.04
7.2.170.0060.00615.12
7.2.60.0040.01117.13
7.2.00.0060.00619.46
7.1.330.0100.00715.77
7.1.320.0000.01515.78
7.1.310.0040.01115.66
7.1.300.0030.01215.59
7.1.290.0110.00415.74
7.1.280.0090.00015.50
7.1.270.0040.00715.84
7.1.260.0050.00515.78
7.1.200.0080.00415.94
7.1.100.0000.01318.21
7.1.70.0040.01217.20
7.1.60.0090.00317.37
7.1.50.0060.00916.84
7.1.40.0060.01216.64
7.1.30.0100.01616.61
7.1.20.0030.01916.65
7.1.10.0000.00916.56
7.1.00.0060.00616.80
7.0.200.0030.00616.94
7.0.190.0060.00616.88
7.0.180.0000.00816.16
7.0.170.0040.00416.21
7.0.160.0000.01316.25
7.0.150.0080.00016.27
7.0.140.0050.00316.23
7.0.130.0040.00416.52
7.0.120.0000.00816.76
7.0.110.0030.00816.59
7.0.100.0050.00516.36
7.0.90.0060.01016.35
7.0.80.0030.01316.59
7.0.70.0030.00516.46
7.0.60.0000.00816.27
7.0.50.0000.00916.37
7.0.40.0030.00915.73
7.0.30.0030.00615.73
7.0.20.0050.00315.73
7.0.10.0030.00615.73
7.0.00.0030.00615.73
5.6.300.0070.03720.79
5.6.290.0060.04120.87
5.6.280.0070.04121.04
5.6.270.0030.04420.92
5.6.260.0070.05320.80
5.6.250.0060.04120.96
5.6.240.0030.06220.99
5.6.230.0030.06920.88
5.6.220.0070.04020.85
5.6.210.0000.04420.98
5.6.200.0030.04120.88
5.6.190.0030.04120.94
5.6.180.0000.08720.84
5.6.170.0000.06220.87
5.6.160.0070.04420.98
5.6.150.0030.05120.98
5.6.140.0130.06620.99
5.6.130.0030.06420.75
5.6.120.0030.04020.79
5.6.110.0070.04320.82
5.6.100.0100.06720.73
5.6.90.0000.04820.79
5.6.80.0070.03620.21
5.6.70.0060.03520.30
5.6.60.0100.04220.39
5.6.50.0000.04020.22
5.6.40.0100.03820.20
5.6.30.0000.04720.34
5.6.20.0100.03320.24
5.6.10.0000.04720.29
5.6.00.0030.04120.32
5.5.380.0030.06517.64
5.5.370.0030.04317.54
5.5.360.0000.06717.66
5.5.350.0030.04717.66
5.5.340.0030.04418.09
5.5.330.0070.03617.75
5.5.320.0030.05718.18
5.5.310.0100.03618.10
5.5.300.0070.05218.12
5.5.290.0030.04218.09
5.5.280.0030.04518.04
5.5.270.0060.04218.08
5.5.260.0030.04218.03
5.5.250.0030.03817.68
5.5.240.0060.03517.48
5.5.230.0130.02917.44
5.5.220.0030.03717.47
5.5.210.0030.03717.51
5.5.200.0030.06317.45
5.5.190.0000.05517.36
5.5.180.0000.04117.38
5.5.160.0030.04117.45
5.5.150.0030.03817.52
5.5.140.0030.03717.05
5.5.130.0000.04017.05
5.5.120.0060.03817.48
5.5.110.0030.03617.34
5.5.100.0030.03717.27
5.5.90.0000.04117.02
5.5.80.0000.03917.09
5.5.70.0030.03717.33
5.5.60.0000.04017.34
5.5.50.0030.03617.32
5.5.40.0040.03617.32
5.5.30.0000.04117.30
5.5.20.0070.03317.36
5.5.10.0030.03617.36
5.5.00.0090.03517.33
5.4.450.0030.04919.40
5.4.440.0060.04519.55
5.4.430.0000.04319.30
5.4.420.0030.03719.30
5.4.410.0030.04619.18
5.4.400.0000.04019.08
5.4.390.0030.03819.14
5.4.380.0070.03419.09
5.4.370.0100.03519.09
5.4.360.0000.04519.21
5.4.350.0040.03919.18
5.4.340.0030.04518.98
5.4.320.0030.03918.93
5.4.310.0030.04118.91
5.4.300.0070.03319.23
5.4.290.0000.03919.21
5.4.280.0000.04919.23
5.4.270.0000.03919.21
5.4.260.0030.03719.16
5.4.250.0070.03619.07
5.4.240.0000.03919.07
5.4.230.0130.05018.92
5.4.220.0030.03719.15
5.4.210.0000.03918.91
5.4.200.0000.04018.99
5.4.190.0030.04319.22
5.4.180.0040.03919.20
5.4.170.0030.03618.94
5.4.160.0000.04019.10
5.4.150.0060.03418.96
5.4.140.0000.04216.73
5.4.130.0030.03416.75
5.4.120.0000.03716.68
5.4.110.0000.03816.54
5.4.100.0070.03516.46
5.4.90.0000.03716.80
5.4.80.0030.03416.52
5.4.70.0000.03716.81
5.4.60.0000.03616.68
5.4.50.0060.03516.46
5.4.40.0030.03716.43
5.4.30.0070.03016.67
5.4.20.0000.04016.71
5.4.10.0070.03316.68
5.4.00.0060.03215.89
5.3.290.0000.04215.73
5.3.280.0000.03915.73
5.3.270.0070.03815.73
5.3.260.0030.03715.73
5.3.250.0030.03515.73
5.3.240.0100.03215.73
5.3.230.0000.03915.73
5.3.220.0030.03515.73
5.3.210.0030.03615.73
5.3.200.0030.03515.73
5.3.190.0060.03215.73
5.3.180.0000.04015.73
5.3.170.0030.04015.73
5.3.160.0060.03215.73
5.3.150.0130.03015.73
5.3.140.0000.04215.73
5.3.130.0000.04015.73
5.3.120.0100.03015.73
5.3.110.0000.04215.73
5.3.100.0040.03515.73
5.3.90.0030.03315.73
5.3.80.0070.04715.73
5.3.70.0070.05215.73
5.3.60.0000.04115.73
5.3.50.0000.03915.73
5.3.40.0000.04215.73
5.3.30.0000.04515.73
5.3.20.0000.04515.73
5.3.10.0000.03515.73
5.3.00.0070.04215.73
5.2.170.0030.04015.73
5.2.160.0030.03015.73
5.2.150.0000.03115.73
5.2.140.0060.03215.73
5.2.130.0000.03115.73
5.2.120.0000.03315.73
5.2.110.0030.02915.73
5.2.100.0030.04115.73
5.2.90.0070.03415.73
5.2.80.0060.04215.73
5.2.70.0000.03315.73
5.2.60.0000.03715.73
5.2.50.0030.03115.73
5.2.40.0060.02815.73
5.2.30.0070.03715.73
5.2.20.0030.02815.73
5.2.10.0000.03715.73
5.2.00.0030.03015.73
5.1.60.0000.02615.73
5.1.50.0030.02215.73
5.1.40.0030.03415.73
5.1.30.0060.02215.73
5.1.20.0000.03115.73
5.1.10.0030.04515.73
5.1.00.0060.02915.73
5.0.50.0070.05015.73
5.0.40.0070.02115.73
5.0.30.0060.03515.73
5.0.20.0030.02515.73
5.0.10.0030.01915.73
5.0.00.0030.05815.73
4.4.90.0000.02115.73
4.4.80.0000.01615.73
4.4.70.0060.01315.73
4.4.60.0030.01415.73
4.4.50.0070.01815.73
4.4.40.0000.03115.73
4.4.30.0030.01415.73
4.4.20.0030.03615.73
4.4.10.0000.01815.73
4.4.00.0030.03715.73
4.3.110.0040.02115.73
4.3.100.0060.02615.73
4.3.90.0030.01315.73
4.3.80.0000.03115.73
4.3.70.0000.02315.73
4.3.60.0030.01215.73
4.3.50.0030.02015.73
4.3.40.0000.02615.73
4.3.30.0060.01215.73
4.3.20.0100.03215.73
4.3.10.0000.01715.73
4.3.00.0000.01815.73

preferences:
47.2 ms | 401 KiB | 5 Q