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); var_dump($parent); return; //$parent['children'] = array(); //$parent['children'][$key] = $sub; } } 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.40.0120.00918.60
8.3.30.0110.00418.72
8.3.20.0080.00018.69
8.3.10.0000.00821.08
8.3.00.0100.00020.50
8.2.170.0100.00722.96
8.2.160.0070.00720.41
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0080.00026.16
8.2.120.0070.00021.13
8.2.110.0080.00320.46
8.2.100.0110.00017.84
8.2.90.0070.00019.25
8.2.80.0060.00317.97
8.2.70.0060.00317.61
8.2.60.0030.00618.05
8.2.50.0050.00518.07
8.2.40.0030.00518.22
8.2.30.0000.00721.11
8.2.20.0000.00817.77
8.2.10.0040.00417.65
8.2.00.0030.00517.70
8.1.270.0040.00423.99
8.1.260.0000.00726.35
8.1.250.0080.00028.09
8.1.240.0100.00022.64
8.1.230.0040.00720.97
8.1.220.0080.00018.77
8.1.210.0000.00818.84
8.1.200.0090.00017.23
8.1.190.0040.00417.54
8.1.180.0040.00418.10
8.1.170.0000.00818.72
8.1.160.0000.00718.98
8.1.150.0040.00418.68
8.1.140.0060.00317.42
8.1.130.0030.00317.87
8.1.120.0000.00717.57
8.1.110.0030.00517.41
8.1.100.0000.00717.54
8.1.90.0000.00817.39
8.1.80.0070.00017.48
8.1.70.0030.00517.38
8.1.60.0040.00417.60
8.1.50.0070.00017.46
8.1.40.0000.00717.52
8.1.30.0030.00517.68
8.1.20.0080.00017.62
8.1.10.0030.00717.57
8.1.00.0040.00417.37
8.0.300.0040.00419.98
8.0.290.0040.00417.16
8.0.280.0000.00718.48
8.0.270.0000.00717.19
8.0.260.0040.00416.85
8.0.250.0040.00416.98
8.0.240.0000.01016.85
8.0.230.0040.00416.96
8.0.220.0070.00016.82
8.0.210.0070.00016.80
8.0.200.0030.00316.99
8.0.190.0060.00317.03
8.0.180.0050.00316.84
8.0.170.0030.00516.98
8.0.160.0040.00417.03
8.0.150.0000.00716.89
8.0.140.0040.00416.86
8.0.130.0030.00613.31
8.0.120.0020.00516.75
8.0.110.0050.00216.96
8.0.100.0040.00416.98
8.0.90.0000.00816.95
8.0.80.0090.00616.95
8.0.70.0030.00516.77
8.0.60.0040.00417.03
8.0.50.0050.00317.00
8.0.30.0120.00717.09
8.0.20.0160.00717.40
8.0.10.0080.00017.11
8.0.00.0090.01316.74
7.4.330.0000.00516.77
7.4.320.0060.00016.64
7.4.300.0000.00616.64
7.4.290.0030.00316.43
7.4.280.0040.00416.63
7.4.270.0070.00016.60
7.4.260.0030.00313.32
7.4.250.0000.00816.53
7.4.240.0000.00716.52
7.4.230.0000.00716.57
7.4.220.0090.00916.39
7.4.210.0090.00916.61
7.4.200.0000.00716.71
7.4.190.0030.00316.47
7.4.160.0150.00616.75
7.4.150.0140.00317.40
7.4.140.0090.00817.86
7.4.130.0140.00616.50
7.4.120.0090.00816.43
7.4.110.0080.00816.75
7.4.100.0030.01316.73
7.4.90.0090.00916.52
7.4.80.0070.01019.39
7.4.70.0060.01216.59
7.4.60.0110.00616.44
7.4.50.0030.00516.39
7.4.40.0060.00922.77
7.4.30.0090.00916.50
7.4.10.0040.01515.20
7.4.00.0070.01015.13
7.3.330.0050.00213.19
7.3.320.0050.00013.30
7.3.310.0030.00316.40
7.3.300.0040.00416.42
7.3.290.0100.00316.42
7.3.280.0070.00916.34
7.3.270.0100.01017.40
7.3.260.0110.01118.24
7.3.250.0120.00616.50
7.3.240.0110.00616.60
7.3.230.0070.01016.47
7.3.210.0030.01416.54
7.3.200.0100.01019.39
7.3.190.0060.01216.25
7.3.180.0160.00216.70
7.3.170.0060.00916.53
7.3.160.0150.00016.38
7.3.130.0030.01214.82
7.3.120.0020.01514.87
7.3.110.0090.00814.56
7.3.100.0080.00814.80
7.3.90.0070.00714.86
7.3.80.0060.00814.74
7.3.70.0110.00514.94
7.3.60.0110.00214.88
7.3.50.0060.00814.87
7.3.40.0070.01014.84
7.3.30.0060.00314.74
7.3.20.0060.00616.50
7.3.10.0040.00916.70
7.3.00.0020.01016.74
7.2.330.0140.01116.61
7.2.320.0060.01216.86
7.2.310.0100.01316.82
7.2.300.0100.00716.80
7.2.290.0120.00616.77
7.2.260.0040.00915.16
7.2.250.0080.01015.17
7.2.240.0050.01015.18
7.2.230.0070.00915.15
7.2.220.0070.00515.16
7.2.210.0040.01115.16
7.2.200.0050.00915.17
7.2.190.0050.00915.07
7.2.180.0060.01014.98
7.2.170.0060.01115.21
7.2.160.0060.00615.00
7.2.150.0100.01017.09
7.2.140.0030.01316.99
7.2.130.0030.01116.94
7.2.120.0080.00516.95
7.2.110.0050.01116.80
7.2.100.0090.00716.87
7.2.90.0100.00616.88
7.2.80.0040.01117.03
7.2.70.0060.00816.95
7.2.60.0110.00217.02
7.2.50.0080.00516.78
7.2.40.0050.01016.77
7.2.30.0030.00916.91
7.2.20.0040.00816.91
7.2.10.0050.00816.74
7.2.00.0040.00917.75
7.1.330.0050.01215.89
7.1.320.0020.01015.93
7.1.310.0060.00915.77
7.1.300.0080.00615.75
7.1.290.0080.00715.92
7.1.280.0070.00615.75
7.1.270.0050.00815.74
7.1.260.0080.00715.93
7.1.250.0030.01215.87
7.1.240.0020.01315.67
7.1.230.0050.00715.88
7.1.220.0070.00715.73
7.1.210.0070.00415.70
7.1.200.0030.01015.82
7.1.190.0060.00715.86
7.1.180.0060.00415.78
7.1.170.0050.00915.98
7.1.160.0050.00915.95
7.1.150.0040.00915.96
7.1.140.0020.00816.00
7.1.130.0040.01015.76
7.1.120.0040.00715.74
7.1.110.0060.00715.88
7.1.100.0030.01016.62
7.1.90.0070.00515.91
7.1.80.0080.00615.84
7.1.70.2990.00715.69
7.1.60.0190.00715.73
7.1.50.0180.00815.41
7.1.40.0170.01015.55
7.1.30.0180.00915.41
7.1.20.0150.01215.45
7.1.10.0160.00915.59
7.1.00.0200.00815.37
7.0.330.0030.01115.27
7.0.320.0050.01015.39
7.0.310.0060.00615.40
7.0.300.0040.01115.46
7.0.290.0050.00515.45
7.0.280.0080.00515.47
7.0.270.0070.00715.50
7.0.260.0050.00615.33
7.0.250.0090.00415.35
7.0.240.0060.00715.35
7.0.230.0020.01015.45
7.0.220.0050.00715.45
7.0.210.0030.01015.36
7.0.200.0270.00715.14
7.0.190.0150.00715.11
7.0.180.0170.00715.25
7.0.170.0190.00515.26
7.0.160.0180.00915.15
7.0.150.0190.00415.25
7.0.140.0130.01015.31
7.0.130.0210.00315.26
7.0.120.1000.00715.24
7.0.110.0240.00915.32
7.0.100.0210.00515.15
7.0.90.0180.00715.34
7.0.80.0210.01015.25
7.0.70.0220.00615.22
7.0.60.0230.00615.17
7.0.50.0240.00315.25
7.0.40.0030.00813.97
7.0.30.0050.00814.02
7.0.20.0050.00814.00
7.0.10.0030.00913.82
7.0.00.0040.00613.94
5.6.400.0000.01814.43
5.6.390.0040.01114.54
5.6.380.0090.00414.21
5.6.370.0070.00514.38
5.6.360.0080.00114.46
5.6.350.0080.00614.39
5.6.340.0060.00314.66
5.6.330.0040.00514.56
5.6.320.0020.01214.45
5.6.310.0050.00414.12
5.6.300.0080.01716.68
5.6.290.0020.03216.52
5.6.280.0040.02616.61
5.6.270.0030.02416.50
5.6.260.0080.01716.71
5.6.250.0070.01816.53
5.6.240.0110.01716.65
5.6.230.0060.02216.52
5.6.220.0070.01816.53
5.6.210.0050.02016.59
5.6.200.0090.01716.63
5.6.190.0060.02316.50
5.6.180.0060.01916.62
5.6.170.0030.02116.64
5.6.160.0060.01816.53
5.6.150.0080.02016.57
5.6.140.0050.02116.71
5.6.130.0050.01716.67
5.6.120.0060.02216.67
5.6.110.0060.02216.53
5.6.100.0070.01616.60
5.6.90.0040.02916.68
5.6.80.0060.02016.19
5.6.70.0040.01916.35
5.6.60.0050.02216.33
5.6.50.0050.01916.39
5.6.40.0030.02116.39
5.6.30.0020.02416.21
5.6.20.0120.01916.22
5.6.10.0070.02016.38
5.6.00.0080.02416.28
5.5.380.0050.03114.37
5.5.370.0050.01914.27
5.5.360.0050.01814.44
5.5.350.0050.02114.34
5.5.340.0120.02014.63
5.5.330.0100.01614.49
5.5.320.0070.01614.68
5.5.310.0060.01714.59
5.5.300.0000.02614.59
5.5.290.0080.01814.57
5.5.280.0040.02014.46
5.5.270.0070.02114.54
5.5.260.0100.01314.62
5.5.250.0000.02414.49
5.5.240.0070.01614.25
5.5.230.0050.02314.33
5.5.220.0080.01614.45
5.5.210.0090.01314.29
5.5.200.0050.01814.28
5.5.190.0050.02013.95
5.5.180.0050.01814.40
5.5.170.0050.00812.51
5.5.160.0080.01514.31
5.5.150.0030.01914.27
5.5.140.0090.01614.37
5.5.130.0060.01914.22
5.5.120.0080.01514.40
5.5.110.0030.02014.22
5.5.100.0050.01814.34
5.5.90.0090.01514.37
5.5.80.0020.02914.15
5.5.70.0050.02014.20
5.5.60.0060.02314.29
5.5.50.0060.01714.17
5.5.40.0070.01714.31
5.5.30.0080.01414.12
5.5.20.0070.01714.18
5.5.10.0050.02114.22
5.5.00.0060.01614.13
5.4.450.0020.02013.75
5.4.440.0100.01513.97
5.4.430.0050.01713.92
5.4.420.0050.01613.84
5.4.410.0070.02213.82
5.4.400.0040.02013.80
5.4.390.0080.01413.79
5.4.380.0120.01113.87
5.4.370.0030.01913.82
5.4.360.0080.01713.63
5.4.350.0090.01313.75
5.4.340.0040.01713.84
5.4.330.0040.00511.18
5.4.320.0040.02013.80
5.4.310.0050.01613.60
5.4.300.0030.01813.69
5.4.290.0030.02013.88
5.4.280.0030.01913.91
5.4.270.0050.02013.82
5.4.260.0080.01413.59
5.4.250.0030.01913.79
5.4.240.0040.01913.52
5.4.230.0030.02313.60
5.4.220.0030.01813.79
5.4.210.0010.02513.75
5.4.200.0040.01913.72
5.4.190.0040.01813.54
5.4.180.0090.01713.70
5.4.170.0030.01713.88
5.4.160.0060.01813.71
5.4.150.0070.01713.80
5.4.140.0040.02012.99
5.4.130.0030.01712.87
5.4.120.0060.01612.99
5.4.110.0060.01812.91
5.4.100.0070.01312.94
5.4.90.0070.02012.89
5.4.80.0050.01612.97
5.4.70.0030.02112.97
5.4.60.0070.01613.18
5.4.50.0040.01712.90
5.4.40.0020.02012.79
5.4.30.0060.01713.02
5.4.20.0030.01513.09
5.4.10.0030.01712.86
5.4.00.0040.01812.94
5.3.290.0040.02112.17
5.3.280.0050.01711.95
5.3.270.0070.01411.99
5.3.260.0070.01512.11
5.3.250.0060.01612.13
5.3.240.0050.01811.84
5.3.230.0060.01612.06
5.3.220.0080.01511.96
5.3.210.0050.01811.98
5.3.200.0050.01811.97
5.3.190.0010.01911.97
5.3.180.0020.02012.03
5.3.170.0050.01411.92
5.3.160.0060.01611.96
5.3.150.0050.01812.09
5.3.140.0050.01611.99
5.3.130.0050.02011.98
5.3.120.0070.01511.95
5.3.110.0040.01611.92
5.3.100.0050.01612.06
5.3.90.0070.01211.99
5.3.80.0040.01711.99
5.3.70.0050.01611.96
5.3.60.0010.01912.06
5.3.50.0030.01511.93
5.3.40.0020.01712.08
5.3.30.0010.02212.06
5.3.20.0050.01711.94
5.3.10.0050.01411.85
5.3.00.0030.01811.85
5.2.170.0050.02212.42
5.2.160.0070.01712.42
5.2.150.0030.02012.42
5.2.140.0040.01912.42
5.2.130.0030.02012.42
5.2.120.0050.01412.42
5.2.110.0050.01812.42
5.2.100.0030.01912.42
5.2.90.0050.01612.42
5.2.80.0030.01812.42
5.2.70.0050.01712.42
5.2.60.0040.01812.42
5.2.50.0030.01912.42
5.2.40.0080.01512.42
5.2.30.0100.01512.42
5.2.20.0030.01712.42
5.2.10.0070.01512.42
5.2.00.0080.01412.42
5.1.60.0030.01512.42
5.1.50.0000.01812.42
5.1.40.0030.01512.42
5.1.30.0030.01512.42
5.1.20.0080.01412.42
5.1.10.0050.01312.42
5.1.00.0010.01712.42
5.0.50.0030.01312.42
5.0.40.0020.01212.42
5.0.30.0040.01912.42
5.0.20.0020.01312.42
5.0.10.0000.01612.42
5.0.00.0050.03012.42
4.4.90.0000.01512.42
4.4.80.0020.01112.42
4.4.70.0020.01212.42
4.4.60.0010.01212.42
4.4.50.0050.00812.42
4.4.40.0030.01512.42
4.4.30.0030.00912.42
4.4.20.0040.00812.42
4.4.10.0020.00912.42
4.4.00.0000.01712.42
4.3.110.0050.01212.42
4.3.100.0010.01012.42
4.3.90.0040.01712.42
4.3.80.0060.01812.42
4.3.70.0020.01112.42
4.3.60.0020.01012.42
4.3.50.0020.01212.42
4.3.40.0050.01212.42
4.3.30.0010.01112.42
4.3.20.0030.00912.42
4.3.10.0030.00912.42
4.3.00.0020.01012.42

preferences:
47.33 ms | 400 KiB | 5 Q