3v4l.org

run code in 300+ PHP versions simultaneously
<?php $qp = [ ['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@0@20000@0"], ['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@12000@0@0"], ['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@0@10000@0"], ['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@10000@0@0"], ['Nsd_id' => "1@2@3@4@5@12", 'Nsd_amount' => "0@0@10000@0@0@1000"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@8000@0@0@0@0@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@0@0@0@0@13000@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@2500@0@3900@0@0@20000@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@5000@0@0@0@0@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@5000@0@0@1000@0@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@2000@0@0@500@0@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@0@0@0@0@4000@0"], ]; $nsdIds = []; $result = []; foreach ($qp as $key => $value) { // exploding Nsd_ids $nsdTemp = explode("@", $value['Nsd_id']); // exploding nsd_amounts $nsdAmount = explode("@", $value['Nsd_amount']); // saving all new nsd ids and only keep unique nsd ids $nsdIds = array_unique(array_merge($nsdIds, $nsdTemp)); // I am now combining keeping nsd id as key and nsd amount as its value $temp1 = array_combine($nsdTemp, $nsdAmount); foreach ($nsdIds as $value1) { // for latest php version // $temp1 contains keys of nsd ids // value1 contains nsdids we are sure that it will be in nsdids as we are already merging those ids // then fetching amounf for that nsdids //$result[$value1] = ($result[$value1] ?? 0) + $temp1[$value1]; // for php version less than 7 $result[$value1] = (!empty($result[$value1]) ? $result[$value1] : 0) + (!empty($temp1[$value1]) ? $temp1[$value1] : 0); } } print_r($result);die;

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.130.0120.00917.57
8.4.120.0090.01020.25
8.4.110.0070.00819.58
8.4.100.0130.00717.55
8.4.90.0150.00620.82
8.4.80.0070.00820.86
8.4.70.0060.00318.85
8.4.60.0060.00418.59
8.4.50.0060.00318.67
8.4.40.0030.00619.68
8.4.30.0030.01622.43
8.4.20.0130.01020.62
8.4.10.0060.00317.95
8.3.260.0130.00716.79
8.3.250.0120.00718.94
8.3.240.0150.00416.72
8.3.230.0100.00716.61
8.3.220.0060.00219.23
8.3.210.0050.00318.45
8.3.200.0060.00316.74
8.3.190.0090.00916.60
8.3.180.0080.01116.80
8.3.170.0090.00918.77
8.3.160.0030.00518.48
8.3.150.0120.00616.55
8.3.140.0040.00419.02
8.3.130.0040.00416.63
8.3.120.0040.00418.88
8.3.110.0030.00620.94
8.3.100.0000.00818.55
8.3.90.0150.00418.43
8.3.80.0060.00618.30
8.3.70.0090.00616.38
8.3.60.0060.01018.68
8.3.50.0100.00818.38
8.3.40.0200.00318.76
8.3.30.0160.00018.77
8.3.20.0060.00323.47
8.3.10.0060.00321.82
8.3.00.0080.00023.65
8.2.290.0150.00416.49
8.2.280.0140.00620.23
8.2.270.0130.00619.02
8.2.260.0090.00618.40
8.2.250.0000.00816.64
8.2.240.0090.00016.99
8.2.230.0060.00322.58
8.2.220.0110.00024.06
8.2.210.0060.00326.77
8.2.200.0060.00318.66
8.2.190.0150.00616.63
8.2.180.0250.01316.35
8.2.170.0140.00719.02
8.2.160.0070.00722.96
8.2.150.0060.00324.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0000.00819.95
8.2.110.0000.00920.51
8.2.100.0040.00817.91
8.2.90.0000.00918.03
8.2.80.0040.00418.05
8.2.70.0050.00318.05
8.2.60.0040.00418.22
8.2.50.0080.00018.10
8.2.40.0040.00420.46
8.2.30.0080.00019.30
8.2.20.0050.00318.00
8.2.10.0000.00719.29
8.2.00.0040.00419.18
8.1.330.0080.00716.10
8.1.320.0120.00716.24
8.1.310.0180.00018.43
8.1.300.0040.00420.13
8.1.290.0060.00318.88
8.1.280.0150.00625.92
8.1.270.0090.00623.80
8.1.260.0080.00326.35
8.1.250.0040.00428.09
8.1.240.0060.00322.11
8.1.230.0060.00622.70
8.1.220.0050.00317.74
8.1.210.0000.00918.77
8.1.200.0060.00317.47
8.1.190.0050.00517.35
8.1.180.0000.00818.10
8.1.170.0030.00618.50
8.1.160.0040.00418.76
8.1.150.0040.00418.84
8.1.140.0070.00018.79
8.1.130.0000.00720.05
8.1.120.0040.00417.46
8.1.110.0040.00417.37
8.1.100.0040.00417.32
8.1.90.0040.00417.45
8.1.80.0030.00517.43
8.1.70.0050.00517.34
8.1.60.0080.00017.52
8.1.50.0040.00417.41
8.1.40.0030.00617.54
8.1.30.0080.00017.55
8.1.20.0040.00417.48
8.1.10.0040.00417.56
8.1.00.0000.00817.57
8.0.300.0000.00720.21
8.0.290.0070.00016.88
8.0.280.0040.00418.34
8.0.270.0000.00816.81
8.0.260.0030.00318.44
8.0.250.0040.00416.97
8.0.240.0040.00416.99
8.0.230.0030.00316.99
8.0.220.0000.00716.98
8.0.210.0000.00716.97
8.0.200.0080.00016.98
8.0.190.0000.00916.93
8.0.180.0040.00416.98
8.0.170.0040.00417.01
8.0.160.0000.00816.92
8.0.150.0050.00216.95
8.0.140.0000.00816.97
8.0.130.0000.00713.38
8.0.120.0050.00217.01
8.0.110.0050.00217.02
8.0.100.0000.00716.75
8.0.90.0070.00016.89
8.0.80.0090.01316.97
8.0.70.0000.00717.02
8.0.60.0000.00816.77
8.0.50.0080.00016.99
8.0.30.0110.00617.03
8.0.20.0180.00016.83
8.0.10.0040.00416.94
8.0.00.0100.00816.79
7.4.330.0000.00515.55
7.4.320.0000.00616.49
7.4.300.0050.00216.64
7.4.290.0040.00416.40
7.4.280.0030.00316.50
7.4.270.0080.00416.45
7.4.260.0030.00316.61
7.4.250.0020.00516.54
7.4.240.0030.00516.57
7.4.230.0030.00516.60
7.4.220.0040.00416.53
7.4.210.0080.00516.53
7.4.200.0070.00016.35
7.4.160.0130.00616.46
7.4.140.0110.00817.86
7.4.130.0030.02016.73
7.4.120.0140.00316.54
7.4.110.0070.01016.34
7.4.100.0080.00816.64
7.4.90.0090.00616.63
7.4.80.0080.00919.39
7.4.70.0030.01316.56
7.4.60.0070.01016.39
7.4.50.0060.00916.55
7.4.40.0070.01616.70
7.4.00.0080.00514.84
7.3.330.0050.00013.23
7.3.320.0000.00713.13
7.3.310.0070.00016.48
7.3.300.0040.00416.30
7.3.290.0070.00016.41
7.3.280.0100.00816.41
7.3.260.0100.00816.48
7.3.240.0060.01116.50
7.3.230.0140.00316.34
7.3.210.0100.00716.64
7.3.200.0120.00916.40
7.3.190.0100.00716.50
7.3.180.0060.01016.52
7.3.170.0200.00316.63
7.3.160.0100.00716.48
7.3.120.0030.01614.78
7.3.110.0060.01214.92
7.3.100.0030.01014.93
7.3.90.0090.00014.58
7.3.80.0030.00714.82
7.3.70.0060.00914.70
7.3.60.0110.00314.79
7.3.50.0110.00514.75
7.3.40.0050.01114.79
7.3.30.0070.00714.70
7.3.20.0140.00515.67
7.3.10.0070.01415.85
7.3.00.0130.00715.91
7.2.330.0090.00916.75
7.2.320.0180.02016.73
7.2.310.0030.01416.53
7.2.300.0050.01116.82
7.2.290.0040.01216.75
7.2.250.0000.02115.07
7.2.240.0130.00914.91
7.2.230.0070.00315.11
7.2.220.0000.01015.10
7.2.210.0030.00915.29
7.2.200.0070.01015.24
7.2.190.0050.01114.98
7.2.180.0070.00714.93
7.2.170.0110.00815.08
7.2.160.0080.00814.88
7.2.150.0140.00815.36
7.2.140.0150.01415.12
7.2.130.0130.00715.04
7.2.120.0070.01614.84
7.2.110.0160.01314.88
7.2.100.0150.00715.18
7.2.90.0170.00315.07
7.2.80.0170.00315.04
7.2.70.0180.01115.08
7.2.60.0140.01414.89
7.2.50.0150.00415.16
7.2.40.0120.01015.20
7.2.30.0090.01215.19
7.2.20.0190.00415.18
7.2.10.0140.01515.11
7.2.00.0120.00315.22
7.1.330.0040.00815.57
7.1.320.0050.00315.87
7.1.310.0080.00315.99
7.1.300.0100.00614.96
7.1.290.0490.00414.75
7.1.280.0140.00414.59
7.1.270.0030.01214.88
7.1.260.0210.00614.85
7.1.250.0120.01514.04

preferences:
29.96 ms | 403 KiB | 5 Q