3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ ['pc', ['pc', null, null], 'id' => 1, 'pid' => 0], ['laptop', ['pc', 'laptop', null], 'id' => 2, 'pid' => 0], ['acc', ['pc', 'acc', null], 'id' => 3, 'pid' => 0], ['bags', ['pc', 'acc', 'bags'], 'id' => 4, 'pid' => 0], ['adapter', ['pc', 'acc', 'adapter'], 'id' => 5, 'pid' => 0], ['clothes', ['clothes', null, null], 'id' => 6, 'pid' => 0] ]; function fillParentIds(array $input): array { return array_values(array_reduce($input, static function ($entriesByPath, $entry) { $hierarchy = array_filter($entry[1]); $pathToParent = implode('/', array_slice($hierarchy, 0, -1)); $pathToEntry = implode('/', $hierarchy); $entry['pid'] = array_key_exists($pathToParent, $entriesByPath) ? $entriesByPath[$pathToParent]['id'] : $entry['id']; $entriesByPath[$pathToEntry] = $entry; return $entriesByPath; }, [])); } print_r(fillParentIds($input));

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.0120.00820.84
8.4.110.0110.01022.38
8.4.100.0070.00518.79
8.4.90.0050.00618.77
8.4.80.0040.00520.58
8.4.70.0140.00717.73
8.4.60.0150.00717.52
8.4.50.0070.00219.37
8.4.40.0130.00719.34
8.4.30.0080.00720.33
8.4.20.0130.00617.85
8.4.10.0090.00019.68
8.3.250.0040.00419.16
8.3.240.0090.01017.01
8.3.230.0120.00716.63
8.3.220.0040.00417.09
8.3.210.0070.00616.57
8.3.200.0060.00216.45
8.3.190.0100.01317.09
8.3.180.0040.00518.53
8.3.170.0090.00617.13
8.3.160.0080.00018.30
8.3.150.0150.00416.86
8.3.140.0030.00518.96
8.3.130.0040.00418.51
8.3.120.0100.00620.63
8.3.110.0030.00620.94
8.3.100.0090.00018.53
8.3.90.0030.00526.77
8.3.80.0110.00019.36
8.3.70.0120.00916.75
8.3.60.0090.00618.29
8.3.50.0130.00823.65
8.3.40.0070.00718.84
8.3.30.0130.00318.85
8.3.20.0060.00320.74
8.3.10.0040.00422.04
8.3.00.0040.00423.71
8.2.290.0120.00720.24
8.2.280.0070.00418.36
8.2.270.0150.00319.05
8.2.260.0150.00616.77
8.2.250.0050.00318.36
8.2.240.0030.00717.28
8.2.230.0030.01222.58
8.2.220.0100.00024.06
8.2.210.0070.01026.77
8.2.200.0080.00018.88
8.2.190.0140.00716.60
8.2.180.0100.01016.88
8.2.170.0050.01019.07
8.2.160.0030.01322.96
8.2.150.0060.00324.18
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0000.00926.16
8.2.110.0030.00621.95
8.2.100.0060.00617.84
8.2.90.0060.00317.91
8.2.80.0080.00019.34
8.2.70.0050.00317.63
8.2.60.0090.00017.63
8.2.50.0030.00717.93
8.2.40.0050.00319.48
8.2.30.0000.00718.21
8.2.20.0000.00718.12
8.2.10.0040.00419.38
8.2.00.0070.00019.34
8.1.330.0120.00621.96
8.1.320.0140.00516.34
8.1.310.0000.00818.32
8.1.300.0060.00318.18
8.1.290.0030.00630.84
8.1.280.0090.00625.92
8.1.270.0030.00522.25
8.1.260.0070.01026.35
8.1.250.0080.00028.09
8.1.240.0040.00422.06
8.1.230.0040.00720.97
8.1.220.0030.00517.74
8.1.210.0090.00018.78
8.1.200.0080.00017.35
8.1.190.0050.00317.35
8.1.180.0000.00818.10
8.1.170.0040.00417.62
8.1.160.0030.00518.83
8.1.150.0070.00019.08
8.1.140.0000.00720.69
8.1.130.0070.00020.12
8.1.120.0000.00717.34
8.1.110.0050.00317.40
8.1.100.0030.00617.44
8.1.90.0080.00317.37
8.1.80.0030.00517.48
8.1.70.0030.00317.43
8.1.60.0050.00317.48
8.1.50.0000.00817.47
8.1.40.0060.00317.53
8.1.30.0040.00417.65
8.1.20.0080.00017.58
8.1.10.0030.00617.54
8.1.00.0000.00717.32
8.0.300.0070.00020.04
8.0.290.0080.00016.63
8.0.280.0070.00018.39
8.0.270.0070.00018.02
8.0.260.0030.00520.03
8.0.250.0030.00616.91
8.0.240.0000.01016.90
8.0.230.0080.00016.76
8.0.220.0030.00316.86
8.0.210.0040.00416.73
8.0.200.0060.00017.01
8.0.190.0050.00317.01
8.0.180.0040.00416.88
8.0.170.0000.00816.81
8.0.160.0000.00816.82
8.0.150.0040.00416.76
8.0.140.0040.00416.85
8.0.130.0000.00613.32
8.0.120.0030.00516.92
8.0.110.0050.00216.76
8.0.100.0000.00716.90
8.0.90.0040.00416.78
8.0.80.0060.00916.91
8.0.70.0030.00516.76
8.0.60.0070.00016.85
8.0.50.0040.00416.80
8.0.30.0070.01017.06
8.0.20.0160.00317.41
8.0.10.0050.00216.90
8.0.00.0100.01616.72
7.4.330.0020.00216.67
7.4.320.0040.00416.66
7.4.300.0000.00616.53
7.4.290.0050.00316.52
7.4.280.0040.00416.52
7.4.270.0030.00616.64
7.4.260.0030.00313.39
7.4.250.0050.00316.50
7.4.240.0060.00216.61
7.4.230.0070.00016.64
7.4.220.0020.00516.55
7.4.210.0110.00616.65
7.4.200.0000.00816.31
7.4.130.0120.01116.54
7.4.120.0060.01416.53
7.4.110.0060.01616.48
7.4.100.0060.01216.51
7.4.90.0030.01316.41
7.4.80.0070.01019.39
7.4.70.0090.01316.52
7.4.60.0100.00616.55
7.4.50.0040.01116.38
7.4.40.0030.01216.47
7.4.10.0060.00814.85
7.4.00.0080.01114.64
7.3.330.0000.00716.39
7.3.320.0000.00513.25
7.3.310.0040.00416.38
7.3.300.0000.00716.40
7.3.290.0020.01316.35
7.3.260.0160.00716.54
7.3.240.0050.01116.51
7.3.230.0080.01516.56
7.3.210.0060.01216.49
7.3.200.0100.00616.67
7.3.190.0070.01016.67
7.3.180.0160.00616.25
7.3.170.0110.01116.36
7.3.160.0110.00416.34
7.3.130.0100.00614.85
7.3.120.0090.00914.77
7.3.110.0070.00714.49
7.3.100.0070.00714.68
7.3.90.0130.00314.71
7.3.80.0130.00314.62
7.3.70.0180.00014.81
7.3.60.0120.00914.79
7.3.50.0180.00714.81
7.3.40.0170.00614.75
7.3.30.0240.00014.83
7.3.20.0130.01314.87
7.3.10.0170.00714.73
7.3.00.0100.01214.70
7.2.330.0130.00416.45
7.2.320.0120.01216.44
7.2.310.0090.00916.45
7.2.300.0100.00716.48
7.2.290.0120.00616.28
7.2.260.0120.00314.94
7.2.250.0060.01115.17
7.2.240.0080.00514.55
7.2.230.0030.01014.89
7.2.220.0090.00614.91
7.2.210.0090.00914.61
7.2.200.0150.00514.85
7.2.190.0200.00314.81
7.2.180.0120.01214.91
7.2.170.0110.00714.82
7.2.160.0190.00614.58
7.2.150.0220.00814.68
7.2.140.0100.01614.91
7.2.130.0080.01214.83
7.2.120.0040.01214.59
7.2.110.0110.00815.03
7.2.100.0060.01214.83
7.2.90.0130.00314.70
7.2.80.0060.00914.93
7.2.70.0100.00714.98
7.2.60.0090.00615.10
7.2.50.0070.01114.71
7.2.40.0060.00915.01
7.2.30.0090.00614.70
7.2.20.0080.00614.91
7.2.10.0120.00514.89
7.2.00.0080.00715.26

preferences:
27.39 ms | 403 KiB | 5 Q