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.0040.01118.43
8.3.50.0150.00722.05
8.3.40.0140.00718.88
8.3.30.0040.01818.82
8.3.20.0090.00018.85
8.3.10.0000.00821.08
8.3.00.0080.00320.83
8.2.180.0140.00716.63
8.2.170.0110.00422.96
8.2.160.0070.00720.39
8.2.150.0040.00424.18
8.2.140.0060.00324.66
8.2.130.0070.00026.16
8.2.120.0050.00320.98
8.2.110.0070.01822.26
8.2.100.0090.00317.97
8.2.90.0040.00417.84
8.2.80.0080.00017.97
8.2.70.0090.00417.38
8.2.60.0050.00317.80
8.2.50.0060.00318.07
8.2.40.0000.00818.16
8.2.30.0060.00321.15
8.2.20.0040.00417.86
8.2.10.0080.00017.78
8.2.00.0040.00417.84
8.1.280.0150.00025.92
8.1.270.0060.00323.99
8.1.260.0110.00426.35
8.1.250.0000.00728.09
8.1.240.0100.01322.19
8.1.230.0040.00822.74
8.1.220.0050.00317.79
8.1.210.0040.00418.77
8.1.200.0060.00317.35
8.1.190.0050.00317.53
8.1.180.0060.00318.10
8.1.170.0000.00818.58
8.1.160.0000.00718.77
8.1.150.0040.00418.61
8.1.140.0070.00017.58
8.1.130.0070.00017.91
8.1.120.0030.00517.56
8.1.110.0000.00917.45
8.1.100.0000.00717.43
8.1.90.0000.00717.39
8.1.80.0080.00017.40
8.1.70.0000.00717.42
8.1.60.0000.00917.49
8.1.50.0040.00417.50
8.1.40.0040.00417.43
8.1.30.0030.00517.63
8.1.20.0040.00417.59
8.1.10.0060.00317.58
8.1.00.0050.00317.37
8.0.300.0080.00019.91
8.0.290.0000.00717.18
8.0.280.0000.00718.35
8.0.270.0000.00717.30
8.0.260.0030.00316.91
8.0.250.0040.00417.00
8.0.240.0060.00317.00
8.0.230.0070.00017.02
8.0.220.0000.00716.88
8.0.210.0040.00417.04
8.0.200.0040.00416.97
8.0.190.0000.00717.09
8.0.180.0050.00217.03
8.0.170.0030.00617.09
8.0.160.0050.00316.88
8.0.150.0030.00517.01
8.0.140.0030.00616.85
8.0.130.0030.00313.30
8.0.120.0020.00517.00
8.0.110.0080.00016.86
8.0.100.0080.00016.86
8.0.90.0040.00417.05
8.0.80.0120.00317.03
8.0.70.0000.00716.81
8.0.60.0040.00416.78
8.0.50.0070.00016.99
8.0.30.0110.00717.16
8.0.20.0150.00617.40
8.0.10.0000.00716.95
8.0.00.0140.01016.79
7.4.330.0020.00216.82
7.4.320.0030.00316.62
7.4.300.0060.00016.65
7.4.290.0070.00016.49
7.4.280.0000.00716.54
7.4.270.0030.00316.66
7.4.260.0000.00613.34
7.4.250.0000.00916.49
7.4.240.0030.00316.59
7.4.230.0050.00216.51
7.4.220.0100.00716.42
7.4.210.0070.00816.48
7.4.200.0030.00316.37
7.4.190.0030.00516.79
7.4.160.0160.00016.50
7.4.150.0070.01017.40
7.4.140.0150.00617.86
7.4.130.0110.00816.57
7.4.120.0090.00916.64
7.4.110.0040.01516.46
7.4.100.0070.01016.53
7.4.90.0090.00916.54
7.4.80.0150.00419.39
7.4.70.0090.00916.54
7.4.60.0070.01016.46
7.4.50.0000.00816.81
7.4.40.0070.01022.77
7.4.30.0130.00616.61
7.4.00.0030.01315.11
7.3.330.0060.00013.41
7.3.320.0030.00313.21
7.3.310.0030.00516.29
7.3.300.0030.00316.39
7.3.290.0070.00716.42
7.3.280.0060.00916.38
7.3.270.0120.00617.40
7.3.260.0100.00918.24
7.3.250.0120.00616.38
7.3.240.0100.00716.65
7.3.230.0100.00616.57
7.3.210.0090.00916.62
7.3.200.0130.00719.39
7.3.190.0090.00816.59
7.3.180.0130.00316.54
7.3.170.0140.00616.57
7.3.160.0120.00516.44
7.3.120.0150.00014.75
7.3.10.0030.01016.73
7.3.00.0080.00416.53
7.2.330.0060.01316.71
7.2.320.0160.00416.79
7.2.310.0130.00416.93
7.2.300.0140.00716.63
7.2.290.0130.00316.77
7.2.130.0080.00516.88
7.2.120.0070.00716.74
7.2.110.0070.00717.01
7.2.100.0090.00016.89
7.2.90.0090.00616.92
7.2.80.0100.00316.78
7.2.70.0060.00616.98
7.2.60.0100.00617.04
7.2.50.0100.00816.75
7.2.40.0090.00617.03
7.2.30.0070.01016.73
7.2.20.0000.01116.95
7.2.10.0060.00616.76
7.2.00.0030.00718.26
7.1.250.0040.00415.52
7.1.200.0030.00915.78
7.1.100.0050.00518.04
7.1.70.0030.01117.32
7.1.60.0070.00717.27
7.1.50.0040.01117.13
7.1.40.0040.01216.39
7.1.30.0110.00616.86
7.1.20.0100.01316.75
7.1.10.0030.00716.48
7.1.00.0060.00316.86
7.0.200.0090.00416.80
7.0.190.0030.01016.69
7.0.180.0070.00716.25
7.0.170.0000.01316.29
7.0.160.0080.00516.33
7.0.150.0040.00416.25
7.0.140.0030.00716.35
7.0.130.0060.00616.66
7.0.120.0000.01016.58
7.0.110.0040.00816.54
7.0.100.0030.00916.25
7.0.90.0060.00616.43
7.0.80.0030.01316.49
7.0.70.0060.01516.46
7.0.60.0000.00816.21
7.0.50.0030.00616.38
7.0.40.0040.00416.21
7.0.30.0000.00716.21
7.0.20.0040.00416.21
7.0.10.0000.01116.21
7.0.00.0040.00816.21
5.6.300.0000.05220.68
5.6.290.0030.04020.80
5.6.280.0030.04020.95
5.6.270.0030.04721.02
5.6.260.0030.04520.87
5.6.250.0030.04920.86
5.6.240.0030.04020.80
5.6.230.0070.08520.83
5.6.220.0000.06920.89
5.6.210.0030.04120.81
5.6.200.0070.04020.84
5.6.190.0000.04620.76
5.6.180.0000.04920.86
5.6.170.0000.04420.92
5.6.160.0240.05120.98
5.6.150.0030.05220.76
5.6.140.0000.04420.84
5.6.130.0030.05420.73
5.6.120.0030.04721.00
5.6.110.0000.04620.74
5.6.100.0070.05720.79
5.6.90.0070.04820.86
5.6.80.0030.04020.21
5.6.70.0100.03820.20
5.6.60.0090.03820.19
5.6.50.0060.03820.35
5.6.40.0030.03820.37
5.6.30.0130.04420.21
5.6.20.0070.05220.25
5.6.10.0000.04520.34
5.6.00.0100.08720.19
5.5.380.0030.04217.64
5.5.370.0000.04617.53
5.5.360.0040.04117.62
5.5.350.0100.03917.62
5.5.340.0030.04017.84
5.5.330.0150.03317.75
5.5.320.0030.04518.18
5.5.310.0040.05618.02
5.5.300.0030.08118.09
5.5.290.0090.04517.74
5.5.280.0070.04318.09
5.5.270.0060.04218.11
5.5.260.0100.06718.12
5.5.250.0070.06917.67
5.5.240.0030.03917.39
5.5.230.0030.04817.13
5.5.220.0100.03517.49
5.5.210.0030.03817.50
5.5.200.0060.04517.45
5.5.190.0070.03917.37
5.5.180.0070.03917.44
5.5.160.0000.04917.35
5.5.150.0030.05017.44
5.5.140.0030.04317.48
5.5.130.0070.06117.31
5.5.120.0060.03817.45
5.5.110.0100.04617.42
5.5.100.0130.03317.36
5.5.90.0030.03817.29
5.5.80.0030.03917.10
5.5.70.0040.03917.24
5.5.60.0000.04116.99
5.5.50.0090.03717.38
5.5.40.0030.04117.41
5.5.30.0000.04717.33
5.5.20.0000.05017.41
5.5.10.0060.03517.07
5.5.00.0000.04317.19
5.4.450.0180.04319.30
5.4.440.0100.04019.30
5.4.430.0070.03419.53
5.4.420.0130.04119.38
5.4.410.0030.05119.30
5.4.400.0090.04318.91
5.4.390.0060.04118.96
5.4.380.0070.04519.07
5.4.370.0060.03519.07
5.4.360.0070.03818.89
5.4.350.0030.03719.13
5.4.340.0070.04619.21
5.4.320.0030.03918.95
5.4.310.0070.05819.16
5.4.300.0000.06018.97
5.4.290.0070.04019.13
5.4.280.0000.04919.16
5.4.270.0070.03919.07
5.4.260.0100.03719.05
5.4.250.0030.04118.97
5.4.240.0000.04619.03
5.4.230.0000.04019.06
5.4.220.0040.04319.10
5.4.210.0030.04519.06
5.4.200.0000.04418.98
5.4.190.0000.03918.89
5.4.180.0000.04019.06
5.4.170.0030.06419.04
5.4.160.0040.04219.18
5.4.150.0030.06119.11
5.4.140.0030.03816.69
5.4.130.0040.06016.48
5.4.120.0030.03516.74
5.4.110.0030.03516.76
5.4.100.0140.04116.68
5.4.90.0070.03416.76
5.4.80.0000.04416.66
5.4.70.0030.06416.79
5.4.60.0000.04116.59
5.4.50.0000.03916.73
5.4.40.0000.03816.51
5.4.30.0100.03116.72
5.4.20.0070.03416.72
5.4.10.0030.03616.45
5.4.00.0100.03216.21
5.3.290.0040.04316.21
5.3.280.0030.03916.21
5.3.270.0030.04116.21
5.3.260.0070.07016.21
5.3.250.0030.06816.21
5.3.240.0030.05216.21
5.3.230.0090.03516.21
5.3.220.0030.05116.21
5.3.210.0030.03716.21
5.3.200.0030.03716.21
5.3.190.0030.03816.21
5.3.180.0000.04216.21
5.3.170.0000.05316.21
5.3.160.0160.04516.21
5.3.150.0000.03916.21
5.3.140.0090.03616.21
5.3.130.0070.04816.21
5.3.120.0070.04516.21
5.3.110.0070.03616.21
5.3.100.0100.03316.21
5.3.90.0030.03516.21
5.3.80.0030.04116.21
5.3.70.0000.03916.21
5.3.60.0000.04116.21
5.3.50.0030.04316.21
5.3.40.0100.04416.21
5.3.30.0030.04416.21
5.3.20.0000.04516.21
5.3.10.0030.03616.21
5.3.00.0000.04316.21
5.2.170.0030.03016.21
5.2.160.0130.03616.21
5.2.150.0040.03216.21
5.2.140.0000.03316.21
5.2.130.0000.03616.21
5.2.120.0090.02616.21
5.2.110.0030.03416.21
5.2.100.0030.03916.21
5.2.90.0030.02816.21
5.2.80.0000.03416.21
5.2.70.0030.02816.21
5.2.60.0030.03016.21
5.2.50.0040.02916.21
5.2.40.0030.03316.21
5.2.30.0030.02816.21
5.2.20.0070.03516.21
5.2.10.0070.02716.21
5.2.00.0040.03216.21
5.1.60.0070.02716.21
5.1.50.0040.02516.21
5.1.40.0070.02116.21
5.1.30.0060.03016.21
5.1.20.0030.02716.21
5.1.10.0030.02416.21
5.1.00.0060.02416.21
5.0.50.0060.01816.21
5.0.40.0030.02016.21
5.0.30.0040.03216.21
5.0.20.0120.01816.21
5.0.10.0030.02116.21
5.0.00.0040.03616.21
4.4.90.0060.01216.21
4.4.80.0040.01416.21
4.4.70.0000.02016.21
4.4.60.0000.01616.21
4.4.50.0030.01316.21
4.4.40.0000.02616.21
4.4.30.0050.01116.21
4.4.20.0030.01616.21
4.4.10.0000.01716.21
4.4.00.0000.02916.21
4.3.110.0030.01716.21
4.3.100.0000.01716.21
4.3.90.0000.01716.21
4.3.80.0060.02116.21
4.3.70.0000.02016.21
4.3.60.0030.02016.21
4.3.50.0000.01916.21
4.3.40.0000.02516.21
4.3.30.0030.01716.21
4.3.20.0070.01016.21
4.3.10.0000.02316.21
4.3.00.0040.01516.21

preferences:
52.97 ms | 401 KiB | 5 Q