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); $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.60.0030.01718.56
8.3.50.0070.01022.03
8.3.40.0110.00418.64
8.3.30.0140.00318.79
8.3.20.0030.00518.95
8.3.10.0030.00521.08
8.3.00.0060.00318.90
8.2.180.0060.01216.50
8.2.170.0110.00422.96
8.2.160.0100.00320.50
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0080.00026.16
8.2.120.0000.00821.18
8.2.110.0060.00320.57
8.2.100.0070.00417.84
8.2.90.0040.00419.36
8.2.80.0040.00419.39
8.2.70.0090.00317.75
8.2.60.0000.00918.05
8.2.50.0040.00418.07
8.2.40.0000.00818.16
8.2.30.0030.00521.20
8.2.20.0000.00817.72
8.2.10.0060.00317.90
8.2.00.0040.00417.79
8.1.280.0060.01225.92
8.1.270.0030.00523.99
8.1.260.0080.00026.35
8.1.250.0000.00828.09
8.1.240.0090.00023.89
8.1.230.0070.00420.71
8.1.220.0040.00418.77
8.1.210.0030.00618.95
8.1.200.0050.00517.11
8.1.190.0000.00817.53
8.1.180.0050.00318.10
8.1.170.0040.00418.63
8.1.160.0000.00818.86
8.1.150.0080.00018.58
8.1.140.0030.00517.56
8.1.130.0040.00417.86
8.1.120.0070.00017.44
8.1.110.0000.00717.44
8.1.100.0040.00417.51
8.1.90.0040.00417.41
8.1.80.0040.00417.49
8.1.70.0030.00317.39
8.1.60.0030.00617.57
8.1.50.0040.00417.38
8.1.40.0050.00217.43
8.1.30.0040.00417.62
8.1.20.0040.00417.69
8.1.10.0080.00017.50
8.1.00.0000.00917.52
8.0.300.0070.00019.90
8.0.290.0040.00417.05
8.0.280.0080.00018.39
8.0.270.0030.00517.30
8.0.260.0030.00316.91
8.0.250.0050.00217.08
8.0.240.0040.00417.09
8.0.230.0030.00317.07
8.0.220.0050.00216.96
8.0.210.0000.00716.98
8.0.200.0030.00316.94
8.0.190.0040.00417.11
8.0.180.0050.00316.94
8.0.170.0080.00017.00
8.0.160.0000.00717.06
8.0.150.0040.00416.95
8.0.140.0030.00516.88
8.0.130.0050.00013.40
8.0.120.0000.00816.96
8.0.110.0000.00816.97
8.0.100.0000.00716.83
8.0.90.0040.00416.80
8.0.80.0090.01216.87
8.0.70.0070.00016.88
8.0.60.0040.00416.83
8.0.50.0000.00716.83
8.0.30.0070.01217.06
8.0.20.0140.01017.40
8.0.10.0000.00716.90
8.0.00.0090.01316.89
7.4.330.0020.00216.71
7.4.320.0060.00016.44
7.4.300.0000.00716.54
7.4.290.0000.00816.44
7.4.280.0030.00316.68
7.4.270.0000.00716.70
7.4.260.0050.00013.35
7.4.250.0000.00716.46
7.4.240.0030.00316.68
7.4.230.0050.00316.71
7.4.220.0060.01316.53
7.4.210.0070.00716.59
7.4.200.0040.00416.45
7.4.190.0040.00416.39
7.4.160.0060.00916.59
7.4.150.0070.01117.40
7.4.140.0110.01217.86
7.4.130.0200.01616.63
7.4.120.0130.00516.67
7.4.110.0100.00716.73
7.4.100.0130.01016.69
7.4.90.0180.00616.39
7.4.80.0090.00919.39
7.4.70.0100.00716.50
7.4.60.0090.00916.58
7.4.50.0040.00416.43
7.4.40.0060.00922.77
7.4.30.0090.00916.59
7.4.10.0080.00815.71
7.4.00.0100.00615.45
7.3.330.0000.00613.21
7.3.320.0030.00313.43
7.3.310.0030.00316.49
7.3.300.0000.00716.48
7.3.290.0070.00716.39
7.3.280.0130.00416.45
7.3.270.0090.00917.40
7.3.260.0100.01018.24
7.3.250.0050.01616.49
7.3.240.0030.01416.48
7.3.230.0070.01016.58
7.3.210.0140.00316.52
7.3.200.0150.00719.39
7.3.190.0150.00916.54
7.3.180.0050.01116.36
7.3.170.0090.00616.67
7.3.160.0030.01316.44
7.3.130.0050.01215.55
7.3.120.0050.01115.57
7.3.110.0050.01215.61
7.3.100.0020.01315.60
7.3.90.0030.00915.54
7.3.80.0040.01215.49
7.3.70.0020.01115.63
7.3.60.0090.00515.64
7.3.50.0120.00115.60
7.3.40.0110.00115.56
7.3.30.0050.00515.68
7.3.20.0080.00517.48
7.3.10.0100.00417.60
7.3.00.0060.00917.35
7.2.330.0120.00616.78
7.2.320.0130.00316.76
7.2.310.0100.01016.75
7.2.300.0060.00916.74
7.2.290.0100.00716.60
7.2.260.0100.00915.75
7.2.250.0060.01215.80
7.2.240.0090.00715.78
7.2.230.0040.00915.59
7.2.220.0040.01015.76
7.2.210.0080.00515.71
7.2.200.0050.00715.76
7.2.190.0060.00815.85
7.2.180.0080.00915.83
7.2.170.0050.00815.61
7.2.160.0030.00815.97
7.2.150.0090.00717.68
7.2.140.0050.00917.64
7.2.130.0060.00817.66
7.2.120.0030.00917.51
7.2.110.0090.00717.59
7.2.100.0050.00817.71
7.2.90.0060.00817.60
7.2.80.0060.00517.63
7.2.70.0020.01617.74
7.2.60.0050.01217.72
7.2.50.0050.01117.58
7.2.40.0020.01417.64
7.2.30.0050.01017.73
7.2.20.0070.00917.62
7.2.10.0110.00217.56
7.2.00.0070.00818.15
7.1.330.0090.00516.66
7.1.320.0070.00716.68
7.1.310.0040.00816.61
7.1.300.0060.00616.47
7.1.290.0040.00716.60
7.1.280.0060.00516.40
7.1.270.0030.00716.37
7.1.260.0050.00716.48
7.1.250.0050.00816.45
7.1.240.0020.01316.54
7.1.230.0040.00616.55
7.1.220.0050.00716.56
7.1.210.0080.00616.44
7.1.200.0010.00916.31
7.1.190.0090.00516.59
7.1.180.0040.01116.68
7.1.170.0110.00316.63
7.1.160.0050.00816.50
7.1.150.0080.00316.47
7.1.140.0080.00816.58
7.1.130.0030.01016.42
7.1.120.0030.01116.51
7.1.110.0080.00816.63
7.1.100.0050.01017.04
7.1.90.0040.00916.68
7.1.80.0060.00816.61
7.1.70.0050.00716.73
7.1.60.0070.01217.43
7.1.50.0130.00822.68
7.1.40.0080.00716.38
7.1.30.0050.00916.62
7.1.20.0050.00916.60
7.1.10.0050.01016.79
7.1.00.0050.01618.54
7.0.330.0020.01116.25
7.0.320.0020.01116.15
7.0.310.0030.00816.22
7.0.300.0040.00916.19
7.0.290.0040.01116.00
7.0.280.0070.00916.04
7.0.270.0020.00816.03
7.0.260.0020.01116.10
7.0.250.0050.00916.10
7.0.240.0080.00416.30
7.0.230.0020.01316.26
7.0.220.0070.00716.29
7.0.210.0060.00716.16
7.0.200.0080.00316.51
7.0.190.0040.00416.09
7.0.180.0010.00916.34
7.0.170.0050.00616.21
7.0.160.0090.00516.18
7.0.150.0040.00916.29
7.0.140.0040.03218.24
7.0.130.0030.00816.27
7.0.120.0050.00916.20
7.0.110.0060.00316.12
7.0.100.0010.01917.44
7.0.90.0080.01617.46
7.0.80.0070.02117.34
7.0.70.0030.02417.32
7.0.60.0100.01417.40
7.0.50.0030.02817.70
7.0.40.0070.01916.14
7.0.30.0050.02016.26
7.0.20.0010.02216.04
7.0.10.0040.02016.15
7.0.00.0070.01616.17
5.6.400.0080.00815.24
5.6.390.0050.00714.94
5.6.380.0030.01215.46
5.6.370.0070.00715.41
5.6.360.0040.00715.31
5.6.350.0040.01015.33
5.6.340.0020.01415.19
5.6.330.0030.01015.05
5.6.320.0090.00314.96
5.6.310.0070.00515.04
5.6.300.0090.00415.38
5.6.290.0100.00315.44
5.6.280.0070.02617.31
5.6.270.0060.00615.11
5.6.260.0030.01115.04
5.6.250.0090.02116.96
5.6.240.0060.02016.95
5.6.230.0060.01817.00
5.6.220.0040.02117.07
5.6.210.0090.01416.91
5.6.200.0020.02317.15
5.6.190.0080.01617.08
5.6.180.0050.02017.11
5.6.170.0070.01617.22
5.6.160.0040.02117.01
5.6.150.0060.01817.07
5.6.140.0060.01917.05
5.6.130.0050.01917.05
5.6.120.0080.03217.02
5.6.110.0030.02517.19
5.6.100.0060.02217.00
5.6.90.0100.02917.03
5.6.80.0020.03716.86
5.6.70.0040.03116.75
5.6.60.0070.02716.77
5.6.50.0060.02216.81
5.6.40.0060.03116.85
5.6.30.0080.01816.84
5.6.20.0100.01716.86
5.6.10.0100.02616.93
5.6.00.0080.03016.80
5.5.380.0040.01717.02
5.5.370.0070.01616.95
5.5.360.0040.01916.92
5.5.350.0060.01816.90
5.5.340.0050.01816.97
5.5.330.0040.02017.07
5.5.320.0060.02017.25
5.5.310.0070.01716.94
5.5.300.0070.01817.03
5.5.290.0020.02317.11
5.5.280.0060.02116.95
5.5.270.0100.02916.97
5.5.260.0040.03817.05
5.5.250.0090.02916.86
5.5.240.0100.02916.80
5.5.230.0050.03316.85
5.5.220.0070.02016.83
5.5.210.0090.03116.90
5.5.200.0130.02416.91
5.5.190.0100.03116.76
5.5.180.0050.02416.76
5.5.170.0090.00414.99
5.5.160.0100.02816.84
5.5.150.0090.02816.93
5.5.140.0050.03316.72
5.5.130.0040.03116.72
5.5.120.0120.02616.91
5.5.110.0090.03016.85
5.5.100.0080.03116.75
5.5.90.0090.02916.83
5.5.80.0040.02516.68
5.5.70.0110.02516.70
5.5.60.0040.03216.67
5.5.50.0060.02916.68
5.5.40.0070.03116.73
5.5.30.0100.02216.68
5.5.20.0090.02016.78
5.5.10.0070.03216.71
5.5.00.0070.02316.69
5.4.450.0020.01814.45
5.4.440.0110.02614.55
5.4.430.0100.02314.48
5.4.420.0090.02214.48
5.4.410.0040.01914.48
5.4.400.0070.02814.29
5.4.390.0030.02914.26
5.4.380.0020.02414.31
5.4.370.0040.03114.20
5.4.360.0060.02814.31
5.4.350.0070.02214.35
5.4.340.0080.01714.20
5.4.330.0030.00711.71
5.4.320.0070.02814.37
5.4.310.0080.02414.23
5.4.300.0100.02414.25
5.4.290.0050.02114.38
5.4.280.0030.03114.13
5.4.270.0060.02914.24
5.4.260.0060.02014.24
5.4.250.0010.02314.27
5.4.240.0080.02614.33
5.4.230.0040.03014.17
5.4.220.0070.03014.32
5.4.210.0090.02414.34
5.4.200.0080.02714.41
5.4.190.0080.02514.15
5.4.180.0030.03114.41
5.4.170.0070.02514.26
5.4.160.0060.02614.32
5.4.150.0090.02214.32
5.4.140.0040.02313.44
5.4.130.0060.02813.41
5.4.120.0060.02413.43
5.4.110.0070.02713.44
5.4.100.0040.03113.44
5.4.90.0060.01713.32
5.4.80.0050.02413.43
5.4.70.0060.02813.59
5.4.60.0040.02913.44
5.4.50.0050.02913.48
5.4.40.0040.02713.48
5.4.30.0080.02413.41
5.4.20.0010.03313.46
5.4.10.0020.02913.48
5.4.00.0030.03013.26
5.3.290.0040.03212.91
5.3.280.0040.02212.84
5.3.270.0070.02512.81
5.3.260.0050.03112.86
5.3.250.0060.02512.87
5.3.240.0060.02912.86
5.3.230.0050.03212.87
5.3.220.0040.02012.85
5.3.210.0010.02612.82
5.3.200.0090.02612.83
5.3.190.0080.01512.91
5.3.180.0050.02912.97
5.3.170.0070.02712.91
5.3.160.0030.03012.95
5.3.150.0070.02912.91
5.3.140.0020.03012.96
5.3.130.0040.02812.88
5.3.120.0040.01912.89
5.3.110.0040.02412.81
5.3.100.0010.02712.69
5.3.90.0040.01912.67
5.3.80.0030.03012.66
5.3.70.0030.03112.68
5.3.60.0010.02212.62
5.3.50.0030.02912.68
5.3.40.0080.01812.58
5.3.30.0030.01712.72
5.3.20.0030.02912.62
5.3.10.0070.01612.46
5.3.00.0030.01812.43
5.2.170.0000.07012.14
5.2.160.0000.06712.14
5.2.150.0070.06012.14
5.2.140.0070.05312.14
5.2.130.0070.03312.14
5.2.120.0130.05312.14
5.2.110.0030.06312.14
5.2.100.0100.05712.14
5.2.90.0070.06012.14
5.2.80.0070.05712.14
5.2.70.0030.06712.14
5.2.60.0070.05312.14
5.2.50.0070.05312.14
5.2.40.0030.04012.14
5.2.30.0030.05312.14
5.2.20.0170.05012.14
5.2.10.0070.06012.14
5.2.00.0030.06012.14
5.1.60.0030.03712.14
5.1.50.0100.03712.14
5.1.40.0030.04712.14
5.1.30.0100.05312.14
5.1.20.0100.05012.14
5.1.10.0030.05312.14
5.1.00.0030.04012.14
5.0.50.0100.03712.14
5.0.40.0030.04312.14
5.0.30.0030.05012.14
5.0.20.0000.04712.14
5.0.10.0030.04312.14
5.0.00.0000.06712.14
4.4.90.0000.03712.14
4.4.80.0030.03712.14
4.4.70.0100.02712.14
4.4.60.0070.03312.14
4.4.50.0030.03312.14
4.4.40.0130.04312.14
4.4.30.0100.03012.14
4.4.20.0070.03312.14
4.4.10.0030.01712.14
4.4.00.0030.05312.14
4.3.110.0000.02712.14
4.3.100.0070.03312.14
4.3.90.0070.03312.14
4.3.80.0030.04012.14
4.3.70.0070.02712.14
4.3.60.0030.03312.14
4.3.50.0030.03712.14
4.3.40.0000.04712.14
4.3.30.0070.03312.14
4.3.20.0000.03712.14
4.3.10.0000.03712.14
4.3.00.0070.03312.14

preferences:
46.13 ms | 401 KiB | 5 Q