3v4l.org

run code in 300+ PHP versions simultaneously
<?php function treeify(array $input): array { $result = []; $path = []; foreach ($input as &$entry) { $entry['children'] = []; $depth = $entry['depth'] - 1; $path = \array_slice($path, 0, $depth); $path[] = &$entry; 0 === $depth ? $result[] = &$entry : $path[$depth - 1]['children'][] = &$entry; } return $result; } print_r(treeify([ ['name' => 'Root_1', 'depth' => 1], ['name' => 'Children', 'depth' => 2], ['name' => 'Children', 'depth' => 2], ['name' => 'Children', 'depth' => 2], ['name' => 'Children', 'depth' => 3], ['name' => 'Children', 'depth' => 3], ['name' => 'Children', 'depth' => 3], ['name' => 'Children', 'depth' => 4], ['name' => 'Children', 'depth' => 2], ['name' => 'Root_2', 'depth'=> 1], ['name' => 'Children', 'depth' => 2], ['name' => 'Children', 'depth' => 2], ['name' => 'Children', 'depth' => 2], ['name' => 'Children', 'depth' => 3], ['name' => 'Root_3', 'depth' => 1], ['name' => 'Root_4', 'depth' => 1], ['name' => 'Children', 'depth' => 2], ]));

Abusive script

This script was stopped while abusing our resources

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.110.0130.00720.94
8.3.100.0040.00424.06
8.3.90.0080.00026.77
8.3.80.0030.00716.75
8.3.70.0150.00416.63
8.3.60.0160.00316.63
8.3.50.0070.00717.38
8.3.40.0100.00618.60
8.3.30.0140.00018.93
8.3.20.0060.00320.57
8.3.10.0080.00020.53
8.3.00.0120.00620.80
8.2.230.0000.01122.58
8.2.220.0040.00837.54
8.2.210.0090.00926.77
8.2.200.0060.00316.50
8.2.190.0150.00616.58
8.2.180.0150.00325.92
8.2.170.0100.00619.04
8.2.160.0000.01422.96
8.2.150.0080.00025.66
8.2.140.0000.00924.66
8.2.130.0050.00326.16
8.2.120.0040.00419.66
8.2.110.0070.00322.27
8.2.100.0060.00619.26
8.2.90.0030.00617.63
8.2.80.0060.00318.91
8.2.70.0040.00417.63
8.2.60.0030.00617.50
8.2.50.0040.00417.61
8.2.40.0050.00319.11
8.2.30.0030.00619.37
8.2.20.0000.00918.16
8.2.10.0070.00019.55
8.2.00.0040.00418.13
8.1.290.0030.00618.88
8.1.280.0090.01225.92
8.1.270.0000.00720.24
8.1.260.0030.00526.35
8.1.250.0040.00428.09
8.1.240.0030.00720.45
8.1.230.0090.00317.77
8.1.220.0030.00517.79
8.1.210.0050.00318.77
8.1.200.0000.00817.35
8.1.190.0050.00317.35
8.1.180.0030.00618.10
8.1.170.0060.00318.54
8.1.160.0040.00419.00
8.1.150.0000.00718.81
8.1.140.0000.00720.27
8.1.130.0030.00320.28
8.1.120.0030.00317.46
8.1.110.0000.00817.46
8.1.100.0040.00417.32
8.1.90.0070.00017.39
8.1.80.0030.00517.38
8.1.70.0040.00417.35
8.1.60.0060.00317.58
8.1.50.0040.00417.49
8.1.40.0040.00417.42
8.1.30.0040.00417.58
8.1.20.0090.00017.64
8.1.10.0040.00417.58
8.1.00.0000.00817.51
8.0.300.0040.00418.77
8.0.290.0000.00816.63
8.0.280.0050.00218.45
8.0.270.0040.00417.28
8.0.260.0000.00818.51
8.0.250.0000.00716.87
8.0.240.0030.00317.04
8.0.230.0030.00616.99
8.0.220.0030.00616.77
8.0.210.0000.00716.79
8.0.200.0040.00416.95
8.0.190.0040.00416.85
8.0.180.0000.00716.89
8.0.170.0080.00016.93
8.0.160.0030.00316.86
8.0.150.0000.00716.88
8.0.140.0030.00316.76
8.0.130.0030.00313.38
8.0.120.0040.00416.89
8.0.110.0040.00416.88
8.0.100.0000.00716.85
8.0.90.0060.00316.77
8.0.80.0100.00716.85
8.0.70.0040.00416.76
8.0.60.0000.00816.92
8.0.50.0000.00716.69
8.0.30.0020.01417.14
8.0.20.0060.01317.40
8.0.10.0040.00416.92
8.0.00.0100.01016.85
7.4.330.0000.00515.55
7.4.320.0000.00616.41
7.4.300.0060.00016.52
7.4.290.0030.00316.55
7.4.280.0000.00716.51
7.4.270.0000.00716.66
7.4.260.0040.00416.59
7.4.250.0000.00816.42
7.4.240.0030.00316.52
7.4.230.0030.00316.31
7.4.220.0000.00816.70
7.4.210.0020.01316.54
7.4.200.0030.00316.51
7.4.160.0090.00816.52
7.4.140.0100.00917.86
7.4.130.0080.01116.48
7.4.120.0100.01416.62
7.4.110.0120.00416.64
7.4.100.0090.00916.40
7.4.90.0110.00616.66
7.4.80.0120.00919.39
7.4.70.0070.01716.58
7.4.60.0070.01416.48
7.4.50.0030.01316.57
7.4.40.0070.01016.45
7.4.10.0100.00315.04
7.4.00.0060.01214.87
7.3.330.0000.00513.15
7.3.320.0000.00513.34
7.3.310.0030.00316.38
7.3.300.0000.00716.38
7.3.290.0030.00316.39
7.3.280.0060.01216.37
7.3.260.0090.00916.48
7.3.240.0070.01216.48
7.3.230.0060.00916.68
7.3.210.0070.01016.66
7.3.200.0170.00816.55
7.3.190.0090.00816.51
7.3.180.0150.00016.33
7.3.170.0100.00716.55
7.3.160.0080.00816.52
7.3.130.0100.01014.99
7.3.120.0040.01414.67
7.3.110.0000.01614.83
7.3.100.0080.00414.76
7.3.90.0090.00614.99
7.3.80.0130.00314.84
7.3.70.0030.01414.91
7.3.60.0000.01415.01
7.3.50.0070.00714.93
7.3.40.0030.00914.93
7.3.30.0040.01514.78
7.3.20.0850.00715.74
7.3.10.0850.00515.82
7.3.00.0880.00315.86
7.2.330.0030.01416.52
7.2.320.0100.00716.69
7.2.310.0030.01516.75
7.2.300.0090.01216.49
7.2.290.0180.00416.79
7.2.260.0090.01215.16
7.2.250.0090.00814.86
7.2.240.0070.01115.08
7.2.230.0040.01214.88
7.2.220.0030.01214.94
7.2.210.0000.01415.35
7.2.200.0070.00715.14
7.2.190.0000.01515.14
7.2.180.0070.00415.08
7.2.170.0120.00315.18
7.2.160.0070.01114.95
7.2.150.0690.00615.98
7.2.140.0810.01115.73
7.2.130.0800.01516.03
7.2.120.0990.00715.83
7.2.110.0880.00615.91
7.2.100.0880.00915.92
7.2.90.1030.00816.01
7.2.80.1180.01316.07
7.2.70.1050.00815.91
7.2.60.1080.01115.82
7.2.50.1090.00815.95
7.2.40.0760.00916.01
7.2.30.0800.00615.96
7.2.20.0810.00715.83
7.2.10.0990.00715.95
7.2.00.1140.00616.05
7.1.330.0110.00415.93
7.1.320.0040.01215.91
7.1.310.0030.00815.95
7.1.300.0070.00715.79
7.1.290.0100.00315.85
7.1.280.0060.00915.83
7.1.270.0040.00815.52
7.1.260.0070.00715.88
7.1.250.0710.00914.70
7.1.240.0040.01116.01
7.1.230.0120.00416.05
7.1.220.0030.01015.54
7.1.210.0120.00415.68
7.1.200.0120.00015.85
7.1.190.0030.01115.80
7.1.180.0100.00715.65
7.1.170.0070.00715.88
7.1.160.0060.00715.79
7.1.150.0030.00615.61
7.1.140.0000.01315.82
7.1.130.0000.01315.83
7.1.120.0100.00015.95
7.1.110.0040.00715.91
7.1.100.0090.00015.86
7.1.90.0030.01015.61
7.1.80.0060.00615.63
7.1.70.0050.00815.97
7.1.60.0000.01615.88
7.1.50.0070.00716.03
7.1.40.0060.00315.81
7.1.30.0030.01015.78
7.1.20.0000.00816.02
7.1.10.0040.01115.95
7.1.00.0070.00715.95

preferences:
31.02 ms | 403 KiB | 5 Q