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; return $out; } } 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.0190.00018.30
8.3.50.0150.00521.14
8.3.40.0110.00418.86
8.3.30.0120.00618.88
8.3.20.0040.00418.82
8.3.10.0040.00421.13
8.3.00.0000.01020.64
8.2.180.0040.01416.50
8.2.170.0120.00322.96
8.2.160.0070.00720.57
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0030.00621.12
8.2.110.0060.00320.51
8.2.100.0110.00017.97
8.2.90.0000.00819.34
8.2.80.0070.00019.21
8.2.70.0090.00417.63
8.2.60.0030.00517.93
8.2.50.0030.00618.07
8.2.40.0040.00418.22
8.2.30.0080.00021.22
8.2.20.0040.00417.71
8.2.10.0000.00817.75
8.2.00.0040.00417.68
8.1.280.0090.00925.92
8.1.270.0000.00823.99
8.1.260.0060.00326.35
8.1.250.0080.00028.09
8.1.240.0060.00322.71
8.1.230.0090.00321.03
8.1.220.0080.00018.77
8.1.210.0030.00618.90
8.1.200.0070.00317.35
8.1.190.0030.00517.51
8.1.180.0030.00618.10
8.1.170.0050.00318.72
8.1.160.0000.00718.96
8.1.150.0070.00018.71
8.1.140.0040.00417.43
8.1.130.0030.00317.90
8.1.120.0000.00717.54
8.1.110.0040.00417.52
8.1.100.0000.00717.38
8.1.90.0000.00717.52
8.1.80.0040.00417.41
8.1.70.0030.00317.47
8.1.60.0060.00317.50
8.1.50.0040.00417.52
8.1.40.0040.00417.57
8.1.30.0050.00217.67
8.1.20.0030.00617.55
8.1.10.0030.00617.45
8.1.00.0000.00817.36
8.0.300.0030.00619.85
8.0.290.0070.00017.05
8.0.280.0000.00718.49
8.0.270.0040.00417.32
8.0.260.0000.00716.83
8.0.250.0000.00716.98
8.0.240.0000.00716.88
8.0.230.0000.00716.87
8.0.220.0030.00316.88
8.0.210.0000.00717.02
8.0.200.0030.00316.99
8.0.190.0040.00416.86
8.0.180.0040.00416.90
8.0.170.0080.00016.98
8.0.160.0040.00416.94
8.0.150.0050.00216.90
8.0.140.0030.00516.83
8.0.130.0030.00313.29
8.0.120.0040.00416.86
8.0.110.0040.00416.82
8.0.100.0000.00716.80
8.0.90.0070.00016.85
8.0.80.0060.00916.96
8.0.70.0040.00416.79
8.0.60.0040.00416.89
8.0.50.0000.00816.87
8.0.30.0130.00617.09
8.0.20.0140.00817.40
8.0.10.0000.00716.96
8.0.00.0070.01516.88
7.4.330.0000.00516.77
7.4.320.0000.00616.55
7.4.300.0000.00616.65
7.4.290.0000.00716.63
7.4.280.0000.00816.50
7.4.270.0030.00316.46
7.4.260.0030.00313.42
7.4.250.0040.00416.42
7.4.240.0040.00416.63
7.4.230.0040.00516.28
7.4.220.0140.01416.63
7.4.210.0070.00916.65
7.4.200.0040.00416.62
7.4.190.0000.00816.70
7.4.160.0150.00316.43
7.4.150.0060.01217.40
7.4.140.0170.00317.86
7.4.130.0090.00816.60
7.4.120.0100.00916.53
7.4.110.0060.01216.57
7.4.100.0130.01016.74
7.4.90.0140.00416.60
7.4.80.0030.01319.39
7.4.70.0070.01516.71
7.4.60.0000.01716.45
7.4.50.0050.00516.63
7.4.40.0060.01022.77
7.4.30.0070.01116.78
7.4.10.0090.01115.21
7.4.00.0070.01014.96
7.3.330.0030.00313.36
7.3.320.0000.00713.18
7.3.310.0030.00316.27
7.3.300.0000.00716.38
7.3.290.0130.00716.29
7.3.280.0090.00716.39
7.3.270.0120.00617.40
7.3.260.0090.01118.24
7.3.250.0090.01016.43
7.3.240.0160.00016.38
7.3.230.0110.00716.54
7.3.210.0140.00316.50
7.3.200.0180.00319.39
7.3.190.0110.00616.32
7.3.180.0060.00916.42
7.3.170.0120.00616.43
7.3.160.0000.01616.57
7.3.130.0100.01014.82
7.3.120.0050.01314.81
7.3.110.0160.00314.91
7.3.100.0100.00314.87
7.3.90.0060.00914.93
7.3.80.0070.00714.49
7.3.70.0040.00815.01
7.3.60.0030.00714.86
7.3.50.0030.00914.84
7.3.40.0030.00614.57
7.3.30.0000.00914.52
7.3.20.0040.00816.51
7.3.10.0100.01016.57
7.3.00.0070.00916.48
7.2.330.0140.00516.81
7.2.320.0070.01116.82
7.2.310.0060.01616.52
7.2.300.0090.01016.54
7.2.290.0030.01916.57
7.2.260.0090.00915.03
7.2.250.0090.01214.95
7.2.240.0030.00914.97
7.2.230.0070.00715.23
7.2.220.0060.00914.86
7.2.210.0050.00515.19
7.2.200.0030.00715.05
7.2.190.0090.00615.24
7.2.180.0030.00915.10
7.2.170.0000.01315.05
7.2.160.0060.00614.82
7.2.150.0000.01316.85
7.2.140.0070.01017.13
7.2.130.0050.01016.80
7.2.120.0130.00416.57
7.2.110.0070.00816.91
7.2.100.0110.00516.50
7.2.90.0090.00916.73
7.2.80.0110.00816.63
7.2.70.0110.00416.81
7.2.60.0090.00816.70
7.2.50.0160.00116.64
7.2.40.0100.01116.80
7.2.30.0110.00616.79
7.2.20.0070.00916.65
7.2.10.0100.00716.58
7.2.00.0090.00517.70
7.1.330.0060.00615.64
7.1.320.0040.01215.70
7.1.310.0070.00315.83
7.1.300.0000.01715.63
7.1.290.0000.00815.75
7.1.280.0070.00715.73
7.1.270.0050.00515.73
7.1.260.0030.00615.57
7.1.250.0070.01015.64
7.1.240.0040.00815.78
7.1.230.0140.00015.74
7.1.220.0030.01015.91
7.1.210.0060.00615.80
7.1.200.0020.00715.83
7.1.190.0060.00315.60
7.1.180.0030.01015.82
7.1.170.0110.00315.61
7.1.160.0070.00315.66
7.1.150.0060.00915.76
7.1.140.0030.00615.83
7.1.130.0030.00715.63
7.1.120.0060.00615.75
7.1.110.0040.00815.60
7.1.100.0030.01117.07
7.1.90.0070.00315.81
7.1.80.0060.00615.93
7.1.70.0050.00616.65
7.1.60.0040.00616.62
7.1.50.0060.01116.51
7.1.40.0080.00415.73
7.1.30.0030.01315.63
7.1.20.0100.01015.76
7.1.10.0040.01415.73
7.1.00.0030.01919.19
7.0.330.0030.01015.55
7.0.320.0040.00415.43
7.0.310.0080.00615.43
7.0.300.0000.01115.37
7.0.290.0030.01015.64
7.0.280.0000.00915.52
7.0.270.0000.01115.38
7.0.260.0070.00715.25
7.0.250.0000.01215.48
7.0.240.0000.01715.39
7.0.230.0040.01115.59
7.0.220.0100.00315.38
7.0.210.0080.00815.57
7.0.200.0030.00916.09
7.0.190.0050.00515.43
7.0.180.0040.01115.55
7.0.170.0040.01115.34
7.0.160.0060.00915.44
7.0.150.0030.01015.49
7.0.140.0030.04218.80
7.0.130.0030.01015.54
7.0.120.0040.01115.66
7.0.110.0100.00315.49
7.0.100.0070.03117.71
7.0.90.0230.04317.52
7.0.80.0050.04417.83
7.0.70.0050.02917.76
7.0.60.0070.04417.84
7.0.50.0260.03717.92
7.0.40.0050.03016.72
7.0.30.0110.04516.79
7.0.20.0070.04016.79
7.0.10.0050.04816.64
7.0.00.0060.04516.75
5.6.400.0070.00714.54
5.6.390.0070.01014.04
5.6.380.0080.00314.33
5.6.370.0090.00014.18
5.6.360.0080.00414.36
5.6.350.0030.01414.77
5.6.340.0070.01014.75
5.6.330.0100.00714.73
5.6.320.0090.00014.60
5.6.310.0060.01014.29
5.6.300.0060.00914.16
5.6.290.0060.00614.41
5.6.280.0050.04017.66
5.6.270.0090.00914.48
5.6.260.0030.00814.26
5.6.250.0070.02317.73
5.6.240.0050.03617.66
5.6.230.0080.04517.56
5.6.220.0000.03117.51
5.6.210.0060.04117.46
5.6.200.0070.04517.72
5.6.190.0080.04317.78
5.6.180.0030.03317.75
5.6.170.0060.03317.74
5.6.160.0080.02817.58
5.6.150.0050.04717.90
5.6.140.0070.02517.82
5.6.130.0050.04317.68
5.6.120.0060.03017.74
5.6.110.0120.04217.79
5.6.100.0050.04817.74
5.6.90.0030.04717.82
5.6.80.0100.03717.33
5.6.70.0050.04517.47
5.6.60.0070.04717.30
5.6.50.0070.04417.45
5.6.40.0050.04317.47
5.6.30.0140.03917.53
5.6.20.0120.03517.36
5.6.10.0020.05017.24
5.6.00.0150.04017.47
5.5.380.0040.02517.39
5.5.370.0070.04117.37
5.5.360.0050.04217.34
5.5.350.0080.04317.37
5.5.340.0080.02517.82
5.5.330.0120.03317.65
5.5.320.0090.02617.63
5.5.310.0070.04517.59
5.5.300.0130.03917.72
5.5.290.0050.04617.73
5.5.280.0060.05117.43
5.5.270.0110.04017.49
5.5.260.0050.03017.64
5.5.250.0020.04317.42
5.5.240.0080.03117.30
5.5.230.0100.04017.19
5.5.220.0030.03217.26
5.5.210.0090.04017.23
5.5.200.0030.04817.26
5.5.190.0050.02817.29
5.5.180.0070.04217.37
5.5.170.0000.01414.53
5.5.160.0110.02617.24
5.5.150.0120.03417.10
5.5.140.0070.04317.22
5.5.130.0030.02517.27
5.5.120.0130.02017.26
5.5.110.0080.04117.25
5.5.100.0050.04217.28
5.5.90.0170.01817.28
5.5.80.0120.04017.02
5.5.70.0070.02817.26
5.5.60.0060.04417.15
5.5.50.0070.04317.34
5.5.40.0100.04117.25
5.5.30.0130.03817.27
5.5.20.0040.04617.19
5.5.10.0110.04017.33
5.5.00.0070.04217.02
5.4.450.0100.03815.45
5.4.440.0110.04415.40
5.4.430.0130.02315.45
5.4.420.0120.04015.39
5.4.410.0140.03515.43
5.4.400.0030.04215.30
5.4.390.0080.04815.26
5.4.380.0050.04115.34
5.4.370.0120.03215.16
5.4.360.0050.04515.24
5.4.350.0080.04015.17
5.4.340.0090.04315.26
5.4.330.0090.00511.43
5.4.320.0110.03715.26
5.4.310.0030.04415.23
5.4.300.0110.03615.29
5.4.290.0100.03215.30
5.4.280.0080.04715.28
5.4.270.0120.03615.28
5.4.260.0070.03915.26
5.4.250.0050.04715.34
5.4.240.0090.02115.29
5.4.230.0090.04115.30
5.4.220.0100.03315.23
5.4.210.0080.04115.17
5.4.200.0040.04515.23
5.4.190.0100.03915.29
5.4.180.0070.04315.26
5.4.170.0090.03915.26
5.4.160.0110.03715.22
5.4.150.0110.04315.14
5.4.140.0090.02813.91
5.4.130.0070.03713.96
5.4.120.0070.04213.91
5.4.110.0090.03213.99
5.4.100.0050.02613.99
5.4.90.0070.04313.99
5.4.80.0130.02813.98
5.4.70.0080.03513.91
5.4.60.0060.02513.93
5.4.50.0040.04213.87
5.4.40.0090.02113.91
5.4.30.0100.03213.91
5.4.20.0070.02513.90
5.4.10.0100.01813.95
5.4.00.0080.02013.67
5.3.290.0100.04313.09
5.3.280.0090.04412.98
5.3.270.0090.03313.02
5.3.260.0090.04313.02
5.3.250.0100.04013.05
5.3.240.0130.03812.99
5.3.230.0080.02612.99
5.3.220.0080.04213.04
5.3.210.0040.04113.01
5.3.200.0090.03813.00
5.3.190.0040.04213.05
5.3.180.0090.02812.99
5.3.170.0120.03513.06
5.3.160.0040.02313.03
5.3.150.0080.03712.99
5.3.140.0070.02412.99
5.3.130.0110.02113.05
5.3.120.0090.02213.01
5.3.110.0040.02513.02
5.3.100.0090.02012.71
5.3.90.0050.02412.75
5.3.80.0060.02412.68
5.3.70.0060.02112.77
5.3.60.0090.01912.67
5.3.50.0040.02312.73
5.3.40.0130.01512.64
5.3.30.0090.02012.73
5.3.20.0060.02012.59
5.3.10.0090.03212.61
5.3.00.0070.01712.56
5.2.170.0100.02011.22
5.2.160.0000.03011.30
5.2.150.0030.02711.15
5.2.140.0000.03011.21
5.2.130.0030.03011.15
5.2.120.0000.02711.15
5.2.110.0000.03011.15
5.2.100.0070.02011.17
5.2.90.0030.03011.15
5.2.80.0030.02711.15
5.2.70.0030.06311.15
5.2.60.0070.02311.15
5.2.50.0000.02711.15
5.2.40.0070.02311.15
5.2.30.0000.03011.15
5.2.20.0030.02711.15
5.2.10.0000.03011.15
5.2.00.0030.02711.15
5.1.60.0000.02711.15
5.1.50.0000.04711.15
5.1.40.0030.02011.15
5.1.30.0030.02311.15
5.1.20.0000.02711.15
5.1.10.0070.02311.15
5.1.00.0100.01711.15
5.0.50.0030.01711.15
5.0.40.0030.02011.15
5.0.30.0030.02311.15
5.0.20.0000.03011.15
5.0.10.0000.02011.15
5.0.00.0000.02711.15
4.4.90.0000.01711.15
4.4.80.0000.01711.15
4.4.70.0030.01011.15
4.4.60.0000.01311.15
4.4.50.0000.01711.15
4.4.40.0030.02011.15
4.4.30.0030.01011.15
4.4.20.0000.01711.15
4.4.10.0000.01711.15
4.4.00.0000.03011.15
4.3.110.0000.01311.15
4.3.100.0000.01311.15
4.3.90.0000.01311.15
4.3.80.0100.01311.15
4.3.70.0000.02311.15
4.3.60.0000.01311.15
4.3.50.0030.01311.15
4.3.40.0000.02311.15
4.3.30.0030.01311.15
4.3.20.0000.01311.15
4.3.10.0000.01311.15
4.3.00.0000.01311.15

preferences:
47.04 ms | 401 KiB | 5 Q