3v4l.org

run code in 300+ PHP versions simultaneously
<?php function replaceParent(&$array, $parent = null) { foreach ($array as &$item) { if ($item['id'] == $parent) { if ($item['parent']) { return replaceParent($array, $item['parent']); } else { return $item['id']; } } elseif ($item['parent']) { $item['parent'] = replaceParent($array, $item['parent']); } } } $array = [ '0' => [ 'id' => 1, 'parent' => 0, 'name' => 'root 0' ], '1' => [ 'id' => 2, 'parent' => 1, 'name' => 'root 1' ], '2' => [ 'id' => 3, 'parent' => 2, 'name' => 'root 2' ], '3' => [ 'id' => 4, 'parent' => 3, 'name' => 'root 3' ], '4' => [ 'id' => 5, 'parent' => 3, 'name' => 'root 4' ], '5' => [ 'id' => 6, 'parent' => 2, 'name' => 'root 2' ] ]; replaceParent($array); var_export($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.4.120.0110.00724.37
8.4.110.0130.00720.45
8.4.100.0050.00319.09
8.4.90.0130.00720.57
8.4.80.0090.00418.75
8.4.70.0080.01317.90
8.4.60.0080.01118.83
8.4.50.0070.01318.64
8.4.40.0030.00619.49
8.4.30.0060.00318.87
8.4.20.0040.01520.83
8.4.10.0040.00417.72
8.3.250.0130.00518.77
8.3.240.0130.00317.09
8.3.230.0100.00816.30
8.3.220.0120.00718.86
8.3.210.0060.00916.60
8.3.200.0060.00316.71
8.3.190.0100.00717.44
8.3.180.0070.00217.26
8.3.170.0140.00420.70
8.3.160.0090.00916.31
8.3.150.0140.00316.67
8.3.140.0070.00717.30
8.3.130.0000.00816.68
8.3.120.0060.00320.67
8.3.110.0080.00320.94
8.3.100.0100.00024.06
8.3.90.0170.00326.77
8.3.80.0100.00018.14
8.3.70.0130.00316.63
8.3.60.0070.01418.56
8.3.50.0090.00418.15
8.3.40.0090.00618.89
8.3.30.0130.00318.79
8.3.20.0080.00020.53
8.3.10.0080.00022.05
8.3.00.0000.00722.39
8.2.290.0130.00620.48
8.2.280.0080.01220.23
8.2.270.0130.00716.62
8.2.260.0140.00416.68
8.2.250.0040.00416.64
8.2.240.0110.00717.00
8.2.230.0060.00322.58
8.2.220.0090.00037.54
8.2.210.0040.00426.77
8.2.200.0000.00916.63
8.2.190.0070.00716.75
8.2.180.0070.01016.63
8.2.170.0150.00022.96
8.2.160.0000.01422.25
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0050.00326.16
8.2.120.0000.00819.76
8.2.110.0030.00620.53
8.2.100.0100.00017.91
8.2.90.0110.00017.75
8.2.80.0060.00318.73
8.2.70.0000.00817.63
8.2.60.0040.00417.93
8.2.50.0040.00418.07
8.2.40.0080.00018.35
8.2.30.0000.00718.18
8.2.20.0040.00417.97
8.2.10.0080.00019.50
8.2.00.0000.00819.25
8.1.330.0100.00922.15
8.1.320.0130.00718.07
8.1.310.0030.00516.10
8.1.300.0090.00020.09
8.1.290.0100.00030.84
8.1.280.0110.00725.92
8.1.270.0080.00023.83
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00718.74
8.1.230.0070.00717.57
8.1.220.0050.00317.74
8.1.210.0000.00918.77
8.1.200.0050.00517.35
8.1.190.0040.00417.35
8.1.180.0050.00318.10
8.1.170.0040.00418.82
8.1.160.0040.00418.93
8.1.150.0000.00718.94
8.1.140.0030.00620.27
8.1.130.0040.00420.11
8.1.120.0070.00017.44
8.1.110.0060.00317.46
8.1.100.0040.00417.46
8.1.90.0040.00717.43
8.1.80.0040.00417.43
8.1.70.0000.00717.34
8.1.60.0030.00617.56
8.1.50.0040.00417.54
8.1.40.0060.00617.41
8.1.30.0040.00417.49
8.1.20.0000.00817.68
8.1.10.0040.00417.55
8.1.00.0060.00317.52
8.0.300.0070.00318.77
8.0.290.0040.00416.75
8.0.280.0040.00418.32
8.0.270.0030.00317.27
8.0.260.0060.00020.11
8.0.250.0000.00816.86
8.0.240.0080.00016.85
8.0.230.0000.00716.99
8.0.220.0030.00316.87
8.0.210.0000.00816.90
8.0.200.0000.00717.00
8.0.190.0070.00016.96
8.0.180.0050.00316.80
8.0.170.0090.00016.91
8.0.160.0000.00817.02
8.0.150.0000.00716.81
8.0.140.0040.00316.77
8.0.130.0060.00013.29
8.0.120.0040.00416.74
8.0.110.0080.00016.90
8.0.100.0080.00016.96
8.0.90.0030.00616.83
8.0.80.0100.00916.86
8.0.70.0040.00416.78
8.0.60.0000.00716.91
8.0.50.0000.00816.91
8.0.30.0130.01017.09
8.0.20.0090.00917.05
8.0.10.0040.00417.08
8.0.00.0120.00616.58
7.4.330.0020.00215.55
7.4.320.0030.00316.60
7.4.300.0030.00316.53
7.4.290.0080.00016.50
7.4.280.0080.00016.52
7.4.270.0070.00016.37
7.4.260.0000.00613.21
7.4.250.0030.00316.59
7.4.240.0020.00516.55
7.4.230.0040.00416.64
7.4.220.0000.00716.51
7.4.210.0060.01016.58
7.4.200.0030.00516.36
7.4.130.0120.00616.58
7.4.120.0070.01416.49
7.4.110.0000.02016.49
7.4.100.0030.01316.59
7.4.90.0100.00716.63
7.4.80.0070.01719.39
7.4.70.0150.00616.59
7.4.60.0070.01016.42
7.4.50.0030.01016.52
7.4.40.0100.00716.20
7.4.00.0080.00814.66
7.3.330.0040.00316.41
7.3.320.0050.00013.16
7.3.310.0040.00416.34
7.3.300.0030.00316.23
7.3.290.0030.01216.36
7.3.260.0090.01016.39
7.3.240.0060.01216.54
7.3.230.0060.01216.45
7.3.210.0100.01316.34
7.3.200.0060.01016.47
7.3.190.0040.01616.45
7.3.180.0060.00916.52
7.3.170.0000.01816.43
7.3.160.0100.00716.39
7.3.100.0040.01114.78
7.3.90.0120.00314.98
7.3.80.0070.00714.47
7.3.70.0090.00514.58
7.3.60.0040.01114.62
7.3.50.0000.01414.91
7.3.40.0070.00714.70
7.3.30.0040.01014.82
7.3.20.0070.01316.75
7.3.10.0180.00016.66
7.3.00.0070.00716.59
7.2.330.0080.01116.70
7.2.320.0090.00916.79
7.2.310.0120.00716.76
7.2.300.0080.01516.75
7.2.290.0110.01116.67
7.2.230.0110.00315.00
7.2.220.0090.00614.89
7.2.210.0040.01114.89
7.2.200.0130.00314.61
7.2.190.0090.00914.84
7.2.180.0110.00314.93
7.2.170.0030.01014.88
7.2.160.0100.00514.95
7.2.150.0040.01716.85
7.2.140.0070.00716.96
7.2.130.0080.00516.75
7.2.120.0060.00916.68
7.2.110.0030.01117.02
7.2.100.0060.00916.95
7.2.90.0090.00616.80
7.2.80.0030.01216.80
7.2.70.0030.01217.07
7.2.60.0060.00816.90
7.2.50.0030.01216.95
7.2.40.0120.00316.96
7.2.30.0060.00816.96
7.2.20.0090.01216.68
7.2.10.0140.00716.84
7.2.00.0100.01116.96
7.1.320.0030.01315.59
7.1.310.0030.01016.02
7.1.300.0040.01515.53
7.1.290.0090.00515.68
7.1.280.0030.01215.86
7.1.270.0030.01515.75
7.1.260.0100.00315.77
7.1.250.0060.00715.95

preferences:
31.27 ms | 403 KiB | 5 Q