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) { if(array_key_exists($key, $array)) { return $array[$key]; } else { 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.0100.01018.63
8.3.50.0130.00521.21
8.3.40.0120.00318.74
8.3.30.0090.00918.84
8.3.20.0060.00318.79
8.3.10.0040.00421.05
8.3.00.0060.00320.70
8.2.180.0160.00617.00
8.2.170.0070.00718.92
8.2.160.0140.00022.96
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0040.00717.75
8.2.110.0050.00520.35
8.2.100.0080.00417.85
8.2.90.0000.00818.16
8.2.80.0020.00519.25
8.2.70.0060.00317.75
8.2.60.0030.00518.05
8.2.50.0060.00318.07
8.2.40.0050.00318.15
8.2.30.0030.00521.21
8.2.20.0000.00717.70
8.2.10.0040.00417.72
8.2.00.0090.00017.72
8.1.280.0110.00425.92
8.1.270.0060.00322.04
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0060.00322.19
8.1.230.0030.00821.04
8.1.220.0040.00417.76
8.1.210.0110.00218.96
8.1.200.0090.00017.23
8.1.190.0050.00317.53
8.1.180.0060.00318.10
8.1.170.0000.00818.64
8.1.160.0070.00018.93
8.1.150.0050.00318.72
8.1.140.0030.00717.36
8.1.130.0030.00317.77
8.1.120.0040.00417.41
8.1.110.0000.00717.36
8.1.100.0030.00617.56
8.1.90.0030.00417.54
8.1.80.0000.00817.47
8.1.70.0030.00317.47
8.1.60.0100.00017.62
8.1.50.0030.00617.51
8.1.40.0050.00317.54
8.1.30.0030.00517.61
8.1.20.0050.00317.66
8.1.10.0060.00317.43
8.1.00.0000.00817.34
8.0.300.0040.00420.11
8.0.290.0000.00817.15
8.0.280.0030.00318.55
8.0.270.0000.00717.21
8.0.260.0070.00016.79
8.0.250.0050.00316.87
8.0.240.0070.00016.86
8.0.230.0000.00717.03
8.0.220.0030.00316.82
8.0.210.0070.00016.97
8.0.200.0070.00017.05
8.0.190.0060.00316.85
8.0.180.0040.00416.86
8.0.170.0000.00716.91
8.0.160.0080.00016.84
8.0.150.0040.00416.88
8.0.140.0040.00416.80
8.0.130.0000.00613.40
8.0.120.0040.00416.91
8.0.110.0040.00416.72
8.0.100.0030.00516.81
8.0.90.0030.00516.80
8.0.80.0070.00716.91
8.0.70.0050.00217.00
8.0.60.0000.00716.79
8.0.50.0040.00416.87
8.0.30.0100.01517.29
8.0.20.0110.00817.40
8.0.10.0050.00317.04
8.0.00.0100.01016.83
7.4.330.0060.00016.84
7.4.320.0030.00316.66
7.4.300.0030.00316.47
7.4.290.0070.00016.56
7.4.280.0000.00716.65
7.4.270.0080.00016.54
7.4.260.0040.00416.38
7.4.250.0000.00816.60
7.4.240.0080.00016.45
7.4.230.0050.00216.63
7.4.220.0100.01316.52
7.4.210.0080.00916.58
7.4.200.0000.00716.64
7.4.190.0070.00016.70
7.4.160.0060.00916.58
7.4.150.0110.00817.40
7.4.140.0100.00817.86
7.4.130.0150.00316.51
7.4.120.0100.01316.40
7.4.110.0060.01216.50
7.4.100.0140.00316.59
7.4.90.0120.00616.52
7.4.80.0080.01319.39
7.4.70.0150.00416.68
7.4.60.0170.00016.59
7.4.50.0030.00616.53
7.4.40.0070.00722.77
7.4.30.0130.01016.38
7.4.00.0080.00814.85
7.3.330.0050.00213.23
7.3.320.0070.00013.30
7.3.310.0040.00416.19
7.3.300.0040.00416.22
7.3.290.0030.01516.45
7.3.280.0060.01116.38
7.3.270.0110.00717.40
7.3.260.0080.01018.24
7.3.250.0060.01116.42
7.3.240.0090.00816.43
7.3.230.0040.01316.39
7.3.210.0100.00716.65
7.3.200.0130.00919.39
7.3.190.0150.00716.60
7.3.180.0140.00716.47
7.3.170.0090.00616.38
7.3.160.0120.00516.68
7.3.120.0100.00514.94
7.3.110.0130.00714.62
7.3.100.0030.01215.04
7.3.90.0000.01214.77
7.3.80.0070.00714.94
7.3.70.0070.00315.02
7.3.60.0110.00415.02
7.3.50.0070.00714.98
7.3.40.0000.01214.64
7.3.30.0060.00614.53
7.3.20.0060.00616.65
7.3.10.0060.00616.75
7.3.00.0080.00716.75
7.2.330.0140.00316.79
7.2.320.0100.00716.82
7.2.310.0080.01516.50
7.2.300.0090.01216.80
7.2.290.0110.00516.59
7.2.250.0130.00615.27
7.2.240.0000.02015.11
7.2.230.0070.00715.13
7.2.220.0060.00315.18
7.2.210.0000.01615.03
7.2.200.0030.00914.87
7.2.190.0080.00815.13
7.2.180.0030.01015.07
7.2.170.0040.01115.11
7.2.130.0040.00716.96
7.2.120.0040.00716.89
7.2.110.0030.01216.96
7.2.100.0070.01016.82
7.2.90.0100.00716.68
7.2.80.0050.01016.86
7.2.70.0030.01316.64
7.2.60.0130.00316.86
7.2.50.0080.00416.91
7.2.40.0060.00316.90
7.2.30.0090.00916.63
7.2.20.0000.01316.87
7.2.10.0060.00616.80
7.2.00.0050.00917.88
7.1.330.0160.00016.00
7.1.320.0070.00315.79
7.1.310.0100.00015.86
7.1.300.0030.00615.70
7.1.290.0060.00915.56
7.1.280.0060.01015.66
7.1.270.0100.00315.84
7.1.260.0100.00315.75
7.1.250.0070.00416.02
7.1.240.0000.01215.56
7.1.230.0070.00715.52
7.1.220.0110.00815.81
7.1.210.0140.00415.72
7.1.200.0150.00715.77
7.1.190.0060.00315.65
7.1.180.0060.00615.61
7.1.170.0070.00315.94
7.1.160.0060.00615.65
7.1.150.0040.01115.55
7.1.140.0090.00315.68
7.1.130.0060.00915.68
7.1.120.0000.00915.39
7.1.110.0000.00915.76
7.1.100.0040.01217.08
7.1.90.0030.01016.03
7.1.80.0040.00815.61
7.1.70.0060.00816.50
7.1.60.0060.00616.50
7.1.50.0060.01016.28
7.1.40.0060.00315.57
7.1.30.0030.00715.28
7.1.20.0060.00315.67
7.1.10.0030.00715.71
7.1.00.0020.02119.10
7.0.330.0080.00815.40
7.0.320.0080.00015.34
7.0.310.0130.00315.39
7.0.300.0090.00315.38
7.0.290.0030.00715.38
7.0.280.0090.00315.29
7.0.270.0070.00715.15
7.0.260.0030.01115.07
7.0.250.0000.00915.50
7.0.240.0030.00514.89
7.0.230.0110.00615.42
7.0.220.0060.00615.45
7.0.210.0060.00315.32
7.0.200.0000.01316.09
7.0.190.0070.00315.25
7.0.180.0030.00615.54
7.0.170.0060.00315.25
7.0.160.0100.00315.14
7.0.150.0030.00715.45
7.0.140.0040.03918.78
7.0.130.0070.00415.55
7.0.120.0090.00615.55
7.0.110.0020.02117.61
7.0.100.0150.02717.63
7.0.90.0160.04017.62
7.0.80.0320.04117.72
7.0.70.0350.03917.52
7.0.60.0370.03517.70
7.0.50.0270.03217.60
7.0.40.0040.02816.63
7.0.30.0110.03516.57
7.0.20.0050.04016.47
7.0.10.0050.04616.48
7.0.00.0050.04216.56
5.6.380.0030.00614.26
5.6.370.0030.01414.65
5.6.360.0060.00614.34
5.6.350.0130.00014.27
5.6.340.0090.00014.24
5.6.330.0000.00814.38
5.6.320.0000.00914.35
5.6.310.0120.00314.75
5.6.300.0040.00814.06
5.6.290.0060.00614.55
5.6.280.0060.04017.55
5.6.270.0040.01214.62
5.6.260.0070.03317.48
5.6.250.0040.03317.47
5.6.240.0050.02817.49
5.6.230.0030.02817.30
5.6.220.0050.02817.46
5.6.210.0070.03017.43
5.6.200.0000.02917.54
5.6.190.0060.04517.38
5.6.180.0030.03917.23
5.6.170.0110.03317.55
5.6.160.0110.02217.32
5.6.150.0050.04517.37
5.6.140.0060.02617.53
5.6.130.0050.02617.53
5.6.120.0030.03217.45
5.6.110.0130.03717.19
5.6.100.0100.02817.33
5.6.90.0080.03017.31
5.6.80.0100.02717.09
5.6.70.0060.02517.19
5.6.60.0030.03717.04
5.6.50.0020.02717.00
5.6.40.0050.03517.21
5.6.30.0090.03017.13
5.6.20.0140.03117.08
5.6.10.0020.04417.16
5.6.00.0050.04317.23
5.5.380.0030.03214.44
5.5.370.0110.04014.31
5.5.360.0050.04414.32
5.5.350.0090.03214.29
5.5.340.0080.03314.53
5.5.330.0070.03714.61
5.5.320.0020.04814.60
5.5.310.0100.03314.74
5.5.300.0020.02714.55
5.5.290.0020.02914.55
5.5.280.0070.02614.42
5.5.270.0030.04214.65
5.5.260.0110.02414.57
5.5.250.0080.02314.62
5.5.240.0030.03514.23
5.5.230.0060.04114.42
5.5.220.0050.04214.19
5.5.210.0050.02914.16
5.5.200.0060.04414.15
5.5.190.0060.02914.36
5.5.180.0070.04014.23
5.5.170.0060.00311.09
5.5.160.0020.03114.24
5.5.150.0100.03414.26
5.5.140.0030.03114.24
5.5.130.0020.02814.23
5.5.120.0070.03214.19
5.5.110.0110.03014.32
5.5.100.0030.04314.16
5.5.90.0050.04314.29
5.5.80.0070.04214.35
5.5.70.0030.04414.37
5.5.60.0020.04014.16
5.5.50.0030.02114.20
5.5.40.0030.04214.21
5.5.30.0070.04014.19
5.5.20.0050.01814.38
5.5.10.0070.03414.10
5.5.00.0080.03614.11
5.4.450.0030.04315.41
5.4.440.0080.03815.38
5.4.430.0080.02015.25
5.4.420.0020.03515.31
5.4.410.0020.02815.37
5.4.400.0070.02915.17
5.4.390.0020.04415.05
5.4.380.0030.03814.98
5.4.370.0050.03615.11
5.4.360.0070.02415.06
5.4.350.0040.02515.10
5.4.340.0080.03715.17
5.4.330.0070.00011.56
5.4.320.0070.03215.28
5.4.310.0050.02415.16
5.4.300.0020.02715.34
5.4.290.0090.03415.08
5.4.280.0020.03715.04
5.4.270.0080.02715.11
5.4.260.0030.02815.21
5.4.250.0030.04015.17
5.4.240.0070.03915.05
5.4.230.0110.02515.10
5.4.220.0020.03515.08
5.4.210.0050.02715.17
5.4.200.0050.02715.04
5.4.190.0080.03215.12
5.4.180.0050.03515.04
5.4.170.0050.02015.12
5.4.160.0080.03615.05
5.4.150.0020.02315.17
5.4.140.0030.03213.70
5.4.130.0070.01713.76
5.4.120.0070.03513.83
5.4.110.0050.03913.89
5.4.100.0020.02413.88
5.4.90.0000.02313.81
5.4.80.0030.02613.88
5.4.70.0050.02713.78
5.4.60.0020.04013.79
5.4.50.0060.02013.75
5.4.40.0030.02313.93
5.4.30.0000.02313.80
5.4.20.0030.03913.85
5.4.10.0020.02613.70
5.4.00.0030.02513.40
5.3.290.0040.03012.91
5.3.280.0040.04312.80
5.3.270.0130.03212.85
5.3.260.0070.03912.81
5.3.250.0080.04012.80
5.3.240.0030.03112.82
5.3.230.0050.03912.83
5.3.220.0040.03512.79
5.3.210.0000.03512.86
5.3.200.0050.03512.78
5.3.190.0050.01812.78
5.3.180.0040.02112.72
5.3.170.0100.03212.80
5.3.160.0050.03912.91
5.3.150.0070.02512.85
5.3.140.0080.03512.71
5.3.130.0050.04012.77
5.3.120.0040.02212.86
5.3.110.0040.02212.79
5.3.100.0080.03512.57
5.3.90.0050.03212.56
5.3.80.0020.03412.59
5.3.70.0030.04012.51
5.3.60.0040.03812.62
5.3.50.0060.02312.42
5.3.40.0100.01612.41
5.3.30.0020.02212.46
5.3.20.0050.03312.33
5.3.10.0000.02412.38
5.3.00.0050.02812.37
5.2.170.0050.02011.58
5.2.160.0070.03011.58
5.2.150.0020.03211.58
5.2.140.0060.02211.58
5.2.130.0080.01611.58
5.2.120.0020.02911.58
5.2.110.0030.02811.58
5.2.100.0050.03011.58
5.2.90.0030.02411.58
5.2.80.0060.02811.58
5.2.70.0030.02111.58
5.2.60.0030.02811.58
5.2.50.0030.01811.58
5.2.40.0020.02111.58
5.2.30.0130.01011.58
5.2.20.0050.01511.58
5.2.10.0050.01511.58
5.2.00.0030.01811.58
5.1.60.0030.02611.58
5.1.50.0030.01511.58
5.1.40.0040.01711.58
5.1.30.0060.01811.58
5.1.20.0020.01511.58
5.1.10.0050.02311.58
5.1.00.0040.03111.58
5.0.50.0020.01311.58
5.0.40.0050.02811.58
5.0.30.0020.03411.58
5.0.20.0020.02511.58
5.0.10.0060.01711.58
5.0.00.0010.02511.58
4.4.90.0020.01411.58
4.4.80.0050.00711.58
4.4.70.0000.02011.58
4.4.60.0050.01311.58
4.4.50.0020.01011.58
4.4.40.0020.02811.58
4.4.30.0050.01211.58
4.4.20.0000.02211.58
4.4.10.0000.01111.58
4.4.00.0050.02611.58
4.3.110.0030.01511.58
4.3.100.0010.01111.58
4.3.90.0020.01611.58
4.3.80.0020.01511.58
4.3.70.0000.01211.58
4.3.60.0000.01211.58
4.3.50.0050.01211.58
4.3.40.0000.01811.58
4.3.30.0050.01011.58
4.3.20.0020.01411.58
4.3.10.0000.01511.58
4.3.00.0000.01411.58

preferences:
39.25 ms | 400 KiB | 5 Q