3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mkProductList($array) { // $tmpVal get product of all elements $tmpVal = 1; // Count zeros in array $cnt = count(array_keys($array, 0)); // If there are two or more zeros, then product of all elements will be zero // No make sense to do // Fill array with zeros and return it if ($cnt > 1) { $array = array_fill_keys(array_keys($array), 0); return $array; } // If there are one or no zeros, then get product of all elements, exclude zero, // cause multiply by zero equal zero foreach($array as $value) { if ($value != 0) { $tmpVal *= $value; } } // If there are one zero, then product of all elements will be zero // exclude zero position in input array, it will be product of all elements if ($cnt == 1) { $array = array_fill_keys(array_keys($array), 0); $array[array_search(0, $array)] = $tmpVal; return $array; } // If there are no zeros, then we replace velues in input array // Product of all elements we devide by current element value // Result is product of all elements, exclude current element value foreach($array as $key => $value) { $array[$key] = $tmpVal / $value; } return $array; } // tests var_dump(producePatStr(array(1,2,3,4))); var_dump(producePatStr(array())); var_dump(producePatStr(array(-0.5, 100, 20))); ?>

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.0140.00516.75
8.3.50.0130.00722.02
8.3.40.0060.00918.93
8.3.30.0090.01218.74
8.3.20.0030.01020.21
8.3.10.0040.00423.53
8.3.00.0000.00819.72
8.2.180.0150.00618.50
8.2.170.0040.01122.96
8.2.160.0140.00020.45
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0000.00919.24
8.2.120.0040.00426.35
8.2.110.0000.00822.25
8.2.100.0060.00617.92
8.2.90.0050.00319.08
8.2.80.0030.00517.97
8.2.70.0000.00817.63
8.2.60.0000.00817.93
8.2.50.0100.00318.07
8.2.40.0080.00022.34
8.2.30.0070.00020.65
8.2.20.0050.00317.81
8.2.10.0040.00417.89
8.2.00.0000.00718.07
8.1.280.0130.00725.92
8.1.270.0070.00020.38
8.1.260.0050.00228.09
8.1.250.0080.00628.09
8.1.240.0130.00723.97
8.1.230.0070.00417.77
8.1.220.0030.00517.74
8.1.210.0030.00618.77
8.1.200.0030.00617.22
8.1.190.0060.00317.10
8.1.180.0040.00418.10
8.1.170.0040.00418.59
8.1.160.0070.00020.65
8.1.150.0040.00418.82
8.1.140.0030.00619.38
8.1.130.0030.00317.47
8.1.120.0040.00417.27
8.1.110.0040.00417.39
8.1.100.0030.00517.23
8.1.90.0040.00417.25
8.1.80.0070.00017.37
8.1.70.0070.00017.31
8.1.60.0040.00417.52
8.1.50.0060.00317.52
8.1.40.0040.00417.43
8.1.30.0040.00417.57
8.1.20.0080.00017.59
8.1.10.0040.00417.55
8.1.00.0030.00517.50
8.0.300.0020.00518.77
8.0.290.0000.00816.63
8.0.280.0000.00718.39
8.0.270.0000.00917.16
8.0.260.0030.00317.31
8.0.250.0020.00516.88
8.0.240.0000.00716.90
8.0.230.0000.00716.95
8.0.220.0020.00516.99
8.0.210.0050.00216.80
8.0.200.0050.00216.85
8.0.190.0050.00316.96
8.0.180.0040.00416.86
8.0.170.0030.00616.90
8.0.160.0050.00316.79
8.0.150.0070.00416.93
8.0.140.0050.00316.82
8.0.130.0000.00613.37
8.0.120.0000.00816.91
8.0.110.0080.00016.77
8.0.100.0050.00216.95
8.0.90.0000.00816.93
8.0.80.0000.01416.89
8.0.70.0040.00416.90
8.0.60.0050.00216.88
8.0.50.0020.00516.72
8.0.30.0120.00817.13
8.0.20.0130.00617.40
8.0.10.0040.00416.92
8.0.00.0120.00916.78
7.4.330.0050.00016.71
7.4.320.0070.00016.40
7.4.300.0030.00316.46
7.4.290.0050.00316.58
7.4.280.0040.00416.36
7.4.270.0030.00316.58
7.4.260.0050.00316.39
7.4.250.0030.00616.47
7.4.240.0060.00116.49
7.4.230.0040.00416.44
7.4.220.0110.00716.57
7.4.210.0090.00916.53
7.4.200.0000.00716.54
7.4.160.0090.00616.33
7.4.150.0100.01017.40
7.4.140.0160.01017.86
7.4.130.0100.01016.45
7.4.120.0090.00916.60
7.4.110.0060.01016.55
7.4.100.0090.01316.43
7.4.90.0110.00716.59
7.4.80.0100.01219.39
7.4.70.0100.00616.39
7.4.60.0030.01316.57
7.4.50.0040.00816.40
7.4.40.0130.00316.45
7.4.30.0080.00816.70
7.4.00.0040.01415.25
7.3.330.0030.00313.30
7.3.320.0050.00013.31
7.3.310.0000.00716.26
7.3.300.0030.00316.39
7.3.290.0030.00316.27
7.3.280.0070.01216.27
7.3.270.0130.00317.40
7.3.260.0140.00316.35
7.3.250.0070.01016.38
7.3.240.0090.01016.47
7.3.230.0090.01016.39
7.3.210.0110.00616.39
7.3.200.0080.00816.55
7.3.190.0110.00616.65
7.3.180.0110.00616.50
7.3.170.0030.01416.42
7.3.160.0030.01316.20
7.3.10.0030.00616.62
7.3.00.0030.00616.57
7.2.330.0150.00316.65
7.2.320.0160.00716.30
7.2.310.0100.01016.67
7.2.300.0100.00716.61
7.2.290.0040.01316.39
7.2.130.0000.01116.86
7.2.120.0030.00616.85
7.2.110.0060.00616.78
7.2.100.0060.00616.65
7.2.90.0000.01216.78
7.2.80.0080.00416.86
7.2.70.0070.00716.62
7.2.60.0060.00816.60
7.2.50.0060.00616.60
7.2.40.0030.00716.70
7.2.30.0030.00916.83
7.2.20.0000.00916.54
7.2.10.0030.00916.67
7.2.00.0090.00517.85
7.1.250.0000.01215.36
7.1.200.0060.00615.64
7.1.100.0050.01017.89
7.1.70.0050.00916.80
7.1.60.0140.01019.52
7.1.50.0040.00816.91
7.1.00.0030.07722.45
7.0.200.0000.01016.48
7.0.60.0070.08319.89
7.0.50.0100.05317.97
7.0.40.0070.09320.40
7.0.30.0300.06320.16
7.0.20.0270.07320.33
7.0.10.0100.06320.23
7.0.00.0070.03720.12
5.6.280.0000.03321.05
5.6.210.0070.08020.55
5.6.200.0100.07718.19
5.6.190.0030.08720.61
5.6.180.0130.06020.61
5.6.170.0330.04720.58
5.6.160.0100.06020.48
5.6.150.0070.08018.23
5.6.140.0170.06018.27
5.6.130.0030.04018.15
5.6.120.0100.08321.02
5.6.110.0070.08320.98
5.6.100.0170.07321.11
5.6.90.0130.05020.96
5.6.80.0070.08020.51
5.5.350.0170.08320.49
5.5.340.0030.03717.96
5.5.330.0100.04020.34
5.5.320.0500.07320.35
5.5.310.0130.04720.27
5.5.300.0130.07717.95
5.5.290.0030.04318.09
5.5.280.0030.08320.98
5.5.270.0070.04720.84
5.5.260.0130.08020.98
5.5.250.0200.05020.50
5.5.240.0330.07020.15

preferences:
32.58 ms | 401 KiB | 5 Q