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) { var_dump($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; $out[$key]['children'] = array(); } else { $parent = &find_by_key($sub['parent_id'], $out); $parent['children'] = array(); $parent['children'][$key] = $sub; var_dump($parent); return; } } return $out; } //var_dump(v1($array)); 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.0060.01218.43
8.3.50.0110.00821.27
8.3.40.0170.00318.83
8.3.30.0040.01418.58
8.3.20.0090.00018.77
8.3.10.0080.00021.08
8.3.00.0050.00320.75
8.2.180.0060.01216.63
8.2.170.0120.00322.96
8.2.160.0070.00720.39
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0000.00721.00
8.2.110.0060.00320.35
8.2.100.0000.01117.91
8.2.90.0050.00318.20
8.2.80.0050.00319.32
8.2.70.0060.00317.59
8.2.60.0030.00617.93
8.2.50.0060.00318.07
8.2.40.0070.00018.16
8.2.30.0030.00621.22
8.2.20.0050.00317.75
8.2.10.0050.00317.84
8.2.00.0040.00417.88
8.1.280.0070.00725.92
8.1.270.0040.00423.99
8.1.260.0040.00426.35
8.1.250.0020.00528.09
8.1.240.0070.00322.15
8.1.230.0120.00020.98
8.1.220.0050.00317.74
8.1.210.0040.00718.82
8.1.200.0070.00317.35
8.1.190.0060.00317.53
8.1.180.0030.00518.10
8.1.170.0060.00318.59
8.1.160.0030.00618.96
8.1.150.0050.00218.59
8.1.140.0050.00317.51
8.1.130.0080.00017.91
8.1.120.0070.00017.52
8.1.110.0040.00417.52
8.1.100.0050.00317.44
8.1.90.0050.00317.41
8.1.80.0000.00817.44
8.1.70.0030.00317.46
8.1.60.0030.00617.60
8.1.50.0000.00817.55
8.1.40.0080.00017.57
8.1.30.0020.00517.66
8.1.20.0000.00817.66
8.1.10.0000.00917.52
8.1.00.0040.00417.47
8.0.300.0080.00020.05
8.0.290.0000.00717.05
8.0.280.0050.00318.52
8.0.270.0000.00717.23
8.0.260.0030.00316.83
8.0.250.0050.00316.96
8.0.240.0080.00016.96
8.0.230.0040.00416.98
8.0.220.0000.00716.98
8.0.210.0000.00716.89
8.0.200.0030.00316.95
8.0.190.0080.00016.97
8.0.180.0040.00416.91
8.0.170.0000.00716.96
8.0.160.0070.00016.82
8.0.150.0000.00716.93
8.0.140.0050.00216.75
8.0.130.0000.00613.44
8.0.120.0000.00716.90
8.0.110.0060.00316.81
8.0.100.0040.00416.98
8.0.90.0000.00716.98
8.0.80.0100.01016.88
8.0.70.0070.00016.99
8.0.60.0070.00016.96
8.0.50.0040.00416.96
8.0.30.0150.00517.06
8.0.20.0160.00317.40
8.0.10.0050.00316.95
8.0.00.0060.01316.93
7.4.330.0030.00316.79
7.4.320.0000.00616.39
7.4.300.0000.00716.54
7.4.290.0030.00316.54
7.4.280.0030.00316.66
7.4.270.0030.00316.47
7.4.260.0060.00013.33
7.4.250.0040.00416.54
7.4.240.0000.00816.44
7.4.230.0000.00716.65
7.4.220.0160.01016.50
7.4.210.0070.00916.56
7.4.200.0040.00416.43
7.4.190.0050.00216.41
7.4.160.0050.01116.66
7.4.150.0060.01217.40
7.4.140.0100.01117.86
7.4.130.0100.01216.61
7.4.120.0050.01216.55
7.4.110.0070.01016.56
7.4.100.0130.01316.47
7.4.90.0070.01116.39
7.4.80.0070.01119.39
7.4.70.0080.01316.55
7.4.60.0000.02016.52
7.4.50.0000.00816.45
7.4.40.0060.00922.77
7.4.30.0130.00716.58
7.4.10.0070.01015.20
7.4.00.0080.00814.99
7.3.330.0000.00513.19
7.3.320.0000.00713.17
7.3.310.0040.00416.35
7.3.300.0000.00716.32
7.3.290.0110.00416.31
7.3.280.0080.00916.36
7.3.270.0070.01117.40
7.3.260.0090.01318.24
7.3.250.0100.00716.62
7.3.240.0100.00616.68
7.3.230.0090.00916.43
7.3.210.0150.00416.27
7.3.200.0140.01219.39
7.3.190.0090.00916.41
7.3.180.0040.01216.45
7.3.170.0060.00916.36
7.3.160.0090.00816.43
7.3.130.0090.00315.12
7.3.120.0060.01114.89
7.3.110.0060.01114.85
7.3.100.0060.01014.85
7.3.90.0100.00514.84
7.3.80.0030.00914.78
7.3.70.0050.00914.89
7.3.60.0050.00614.77
7.3.50.0030.00914.79
7.3.40.0000.01414.81
7.3.30.0000.01514.83
7.3.20.0070.00616.68
7.3.10.0060.00616.67
7.3.00.0060.00716.71
7.2.330.0140.00516.86
7.2.320.0140.00316.80
7.2.310.0030.01316.77
7.2.300.0130.00316.46
7.2.290.0030.01316.73
7.2.260.0060.00915.19
7.2.250.0070.01015.01
7.2.240.0040.01415.19
7.2.230.0070.01015.09
7.2.220.0070.00715.06
7.2.210.0070.00315.14
7.2.200.0020.01114.93
7.2.190.0020.01215.09
7.2.180.0080.00715.16
7.2.170.0050.01015.11
7.2.160.0080.00314.96
7.2.150.0060.00816.88
7.2.140.0030.01016.89
7.2.130.0050.00816.86
7.2.120.0060.00617.00
7.2.110.0060.00717.08
7.2.100.0050.00816.88
7.2.90.0060.00616.94
7.2.80.0060.00817.01
7.2.70.0070.00517.01
7.2.60.0060.00816.96
7.2.50.0050.00616.83
7.2.40.0080.00816.94
7.2.30.0070.00716.93
7.2.20.0060.00916.84
7.2.10.0080.00517.01
7.2.00.0040.01016.88
7.1.330.0020.01115.64
7.1.320.0080.00515.74
7.1.310.0080.00515.76
7.1.300.0050.00515.72
7.1.290.0050.00515.93
7.1.280.0070.00315.71
7.1.270.0070.00515.90
7.1.260.0070.00915.74
7.1.250.0040.00815.82
7.1.240.0110.00015.80
7.1.230.0100.00315.64
7.1.220.0080.00815.89
7.1.210.0060.00615.77
7.1.200.0070.00715.61
7.1.190.0070.00715.78
7.1.180.0060.00615.84
7.1.170.0060.00616.00
7.1.160.0070.00715.46
7.1.150.0070.00715.84
7.1.140.0030.00915.86
7.1.130.0160.00015.95
7.1.120.0030.01015.80
7.1.110.0070.00315.86
7.1.100.0040.01116.03
7.1.90.0040.01215.79
7.1.80.0030.01016.02
7.1.70.0040.00516.49
7.1.60.0060.00616.54
7.1.50.0050.01016.48
7.1.40.0070.00715.84
7.1.30.0030.00715.60
7.1.20.0030.00715.95
7.1.10.0050.00515.85
7.1.00.0060.02319.12
7.0.330.0080.00415.38
7.0.320.0000.00815.42
7.0.310.0030.01315.53
7.0.300.0100.00315.43
7.0.290.0030.00615.67
7.0.280.0070.00715.21
7.0.270.0000.01315.55
7.0.260.0060.00315.42
7.0.250.0000.00915.28
7.0.240.0110.00415.26
7.0.230.0000.01415.64
7.0.220.0000.01615.65
7.0.210.0000.01215.23
7.0.200.0050.01016.03
7.0.190.0080.00015.46
7.0.180.0070.00715.37
7.0.170.0030.00715.52
7.0.160.0070.00715.44
7.0.150.0060.00815.33
7.0.140.0080.04118.68
7.0.130.0000.01015.28
7.0.120.0000.01115.43
7.0.110.0000.01315.25
7.0.100.0040.00915.20
7.0.90.0000.01215.47
7.0.80.0030.00615.42
7.0.70.0040.00415.36
7.0.60.0100.04717.70
7.0.50.0060.02416.70
7.0.40.0080.02216.82
7.0.30.0100.02816.75
7.0.20.0120.03516.93
7.0.10.0180.02216.85
7.0.00.0070.02716.98
5.6.400.0030.01014.71
5.6.390.0000.01514.08
5.6.380.0090.00314.04
5.6.370.0060.00314.44
5.6.360.0030.01014.18
5.6.350.0070.00714.44
5.6.340.0100.00014.45
5.6.330.0000.01514.92
5.6.320.0090.00614.70
5.6.310.0030.01014.71
5.6.300.0040.01114.25
5.6.290.0120.00614.20
5.6.280.0070.04017.66
5.6.270.0000.01114.17
5.6.260.0000.01414.23
5.6.250.0000.01114.60
5.6.240.0030.00914.44
5.6.230.0060.00614.51
5.6.220.0040.01114.54
5.6.210.0070.04717.40
5.6.200.0050.03516.34
5.6.190.0060.04517.51
5.6.180.0180.03317.42
5.6.170.0250.04517.37
5.6.160.0050.02917.57
5.6.150.0050.04516.38
5.6.140.0100.03816.22
5.6.130.0040.03516.19
5.6.120.0060.04717.73
5.6.110.0070.02217.87
5.6.100.0050.02217.67
5.6.90.0050.04117.64
5.6.80.0100.04317.47
5.6.70.1490.02417.33
5.6.60.0040.01114.23
5.6.50.0060.01014.36
5.6.40.0090.00614.65
5.6.30.0100.00714.16
5.6.20.0130.00314.40
5.6.10.0070.00714.23
5.6.00.0060.00914.50
5.5.380.0030.00914.34
5.5.370.0080.00414.62
5.5.360.0080.00414.51
5.5.350.0180.03817.55
5.5.340.0070.03216.20
5.5.330.0070.04217.35
5.5.320.0080.04617.44
5.5.310.0170.03817.32
5.5.300.0080.02916.15
5.5.290.0050.04316.33
5.5.280.0060.04517.50
5.5.270.0030.03217.66
5.5.260.0070.04917.51
5.5.250.0050.05017.47
5.5.240.0160.03917.27
5.5.230.0040.01514.70
5.5.220.0040.01514.31
5.5.210.0070.01014.31
5.5.200.0000.01414.27
5.5.190.0060.00914.51
5.5.180.0040.01114.11
5.5.170.0040.00714.44
5.5.160.0110.00314.25
5.5.150.0000.01514.05
5.5.140.0120.00314.35
5.5.130.0110.00614.16
5.5.120.0040.00914.49
5.5.110.0080.01214.41
5.5.100.0070.01014.43
5.5.90.0040.01614.28
5.5.80.0110.00414.37
5.5.70.0000.01313.96
5.5.60.0030.01014.28
5.5.50.0060.00614.55
5.5.40.0130.00014.24
5.5.30.0030.01614.39
5.5.20.0070.00714.22
5.5.10.0030.00714.25
5.5.00.0130.00314.34
5.4.450.0230.04115.32
5.4.440.0250.02715.29
5.4.430.0230.02315.27
5.4.420.0150.02315.26
5.4.410.0220.02115.37
5.4.400.0170.03715.16
5.4.390.0240.04015.04
5.4.380.0280.02115.28
5.4.370.0220.03715.12
5.4.360.0170.02714.96
5.4.350.0190.02315.22
5.4.340.0200.03115.00
5.4.330.0030.00910.70
5.4.320.0210.03315.13
5.4.310.0160.02314.96
5.4.300.0190.01815.14
5.4.290.0230.02415.03
5.4.280.0150.02715.01
5.4.270.0290.03515.15
5.4.260.0190.02415.06
5.4.250.0170.02214.97
5.4.240.0170.02015.13
5.4.230.0170.02815.24
5.4.220.0150.02915.18
5.4.210.0220.03715.23
5.4.200.0220.02314.96
5.4.190.0210.02015.34
5.4.180.0190.02515.09
5.4.170.0200.02215.12
5.4.160.0250.03415.31
5.4.150.0200.02015.14
5.4.140.0200.03913.81
5.4.130.0200.01813.73
5.4.120.0230.01513.87
5.4.110.0180.02213.96
5.4.100.0200.03213.60
5.4.90.0230.03213.86
5.4.80.0220.02213.76
5.4.70.0210.02313.79
5.4.60.0210.01613.86
5.4.50.0240.03013.81
5.4.40.0260.03213.73
5.4.30.0250.02713.77
5.4.20.0280.02513.79
5.4.10.0300.02713.66
5.4.00.0190.02213.56
5.3.290.0180.02912.74
5.3.280.0200.02312.66
5.3.270.0260.03212.66
5.3.260.0260.04112.56
5.3.250.0280.03212.61
5.3.240.0170.02812.74
5.3.230.0210.03812.49
5.3.220.0180.02512.60
5.3.210.0230.03312.54
5.3.200.0210.04012.66
5.3.190.0180.03012.71
5.3.180.0230.03112.63
5.3.170.0220.02212.70
5.3.160.0150.02312.59
5.3.150.0170.02412.60
5.3.140.0180.02012.75
5.3.130.0170.02812.60
5.3.120.0240.03612.48
5.3.110.0250.02512.52
5.3.100.0230.03512.39
5.3.90.0200.03212.48
5.3.80.0260.03012.35
5.3.70.0250.03812.43
5.3.60.0200.02312.24
5.3.50.0280.03012.18
5.3.40.0230.02512.17
5.3.30.0240.03212.21
5.3.20.0230.03012.11
5.3.10.0250.03311.96
5.3.00.0230.03511.91
5.2.170.0330.04012.17
5.2.160.0300.06012.17
5.2.150.0230.03712.17
5.2.140.0370.03712.17
5.2.130.0330.05312.17
5.2.120.0370.05012.17
5.2.110.0470.03712.17
5.2.100.0300.04012.17
5.2.90.0230.03712.17
5.2.80.0400.05312.17
5.2.70.0270.03312.17
5.2.60.0370.05012.17
5.2.50.0370.04312.17
5.2.40.0300.05312.17
5.2.30.0330.05312.17
5.2.20.0400.04712.17
5.2.10.0300.03712.17
5.2.00.0270.04312.17
5.1.60.0300.05012.17
5.1.50.0330.02712.17
5.1.40.0330.04712.17
5.1.30.0300.05312.17
5.1.20.0200.03312.17
5.1.10.0330.04312.17
5.1.00.0270.02712.17
5.0.50.0100.02712.17
5.0.40.0130.02312.17
5.0.30.0170.06012.17
5.0.20.0200.02712.17
5.0.10.0200.03712.17
5.0.00.0100.05012.17
4.4.90.0200.01312.17
4.4.80.0170.03012.17
4.4.70.0170.02012.17
4.4.60.0100.02012.17
4.4.50.0130.03312.17
4.4.40.0230.04312.17
4.4.30.0130.02312.17
4.4.20.0100.02012.17
4.4.10.0130.03712.17
4.4.00.0170.03312.17
4.3.110.0170.02012.17
4.3.100.0170.03012.17
4.3.90.0100.02312.17
4.3.80.0130.02312.17
4.3.70.0170.03012.17
4.3.60.0070.02012.17
4.3.50.0130.03712.17
4.3.40.0170.03312.17
4.3.30.0070.02712.17
4.3.20.0070.03312.17
4.3.10.0130.03712.17
4.3.00.0130.03012.17

preferences:
52.4 ms | 401 KiB | 5 Q