3v4l.org

run code in 300+ PHP versions simultaneously
<?php function freqCount(array $values, $searchValue): array { $frequencies = computeFrequencies($values, $searchValue, 0); return array_map(static fn($key) => [$key, $frequencies[$key]], array_keys($frequencies)); } function computeFrequencies(array $values, $searchValue, int $depth): array { $frequencies = [$depth => 0]; foreach ($values as $value) { if ($value === $searchValue) { $frequencies[$depth]++; } elseif (is_array($value)) { foreach (computeFrequencies($value, $searchValue, $depth + 1) as $deeperDepth => $frequency) { $frequencies[$deeperDepth] = ($frequencies[$deeperDepth] ?? 0) + $frequency; } } } return $frequencies; } print_r(freqCount([1, 4, 4, [1, 1, [1, 2, 1, 1]]], 1)); print_r(freqCount([1, 5, 5, [5, [1, 2, 1, 1], 5, 5], 5, [5]], 5)); print_r(freqCount([1, [2], 1, [[2]], 1, [[[2]]], 1, [[[[2]]]]], 2));

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.5.10.0110.00616.89
8.5.00.0110.01020.02
8.4.160.0110.01121.96
8.4.150.0030.00014.05
8.4.140.0080.01317.76
8.4.130.0140.00619.32
8.4.120.0050.00720.66
8.4.110.0060.01222.71
8.4.100.0130.00717.66
8.4.90.0120.00918.55
8.4.80.0100.00717.71
8.4.70.0120.00717.64
8.4.60.0170.00618.66
8.4.50.0060.00320.32
8.4.40.0100.01017.92
8.4.30.0100.00018.63
8.4.20.0100.00617.85
8.4.10.0130.00619.69
8.3.290.0120.00820.85
8.3.280.0170.00818.34
8.3.270.0120.00816.68
8.3.260.0080.00816.45
8.3.250.0150.00519.12
8.3.240.0090.00916.64
8.3.230.0100.00916.48
8.3.220.0070.00517.30
8.3.210.0060.00216.76
8.3.200.0040.00416.65
8.3.190.0040.00417.19
8.3.180.0080.00316.54
8.3.170.0080.00017.48
8.3.160.0100.00918.19
8.3.150.0050.00320.75
8.3.140.0130.00617.25
8.3.130.0040.00416.64
8.3.120.0040.00719.08
8.3.110.0030.00718.59
8.3.100.0120.00316.53
8.3.90.0040.00426.77
8.3.80.0060.00316.75
8.3.70.0030.01316.61
8.3.60.0060.01216.50
8.3.50.0140.00824.51
8.3.40.0120.00321.86
8.3.30.0070.00718.85
8.3.20.0000.00824.18
8.3.10.0080.00024.66
8.3.00.0050.00326.16
8.2.300.0120.00722.20
8.2.290.0090.01020.52
8.2.280.0060.00518.61
8.2.270.0090.00916.99
8.2.260.0080.00020.02
8.2.250.0090.00018.38
8.2.240.0030.00617.26
8.2.230.0040.01120.94
8.2.220.0000.00724.06
8.2.210.0050.00326.77
8.2.200.0000.00916.75
8.2.190.0070.00716.63
8.2.180.0110.00425.92
8.2.170.0060.01218.89
8.2.160.0080.00522.96
8.2.150.0050.00225.66
8.2.140.0090.00024.66
8.2.130.0050.00326.16
8.2.120.0060.00320.85
8.2.110.0070.01021.13
8.2.100.0000.01217.84
8.2.90.0040.00419.57
8.2.80.0040.00418.03
8.2.70.0040.00417.79
8.2.60.0080.00018.09
8.2.50.0030.00518.10
8.2.40.0030.00719.29
8.2.30.0050.00219.25
8.2.20.0040.00418.15
8.2.10.0000.00919.32
8.2.00.0040.00419.32
8.1.330.0120.00621.79
8.1.320.0120.00716.11
8.1.310.0070.01116.85
8.1.300.0040.00417.99
8.1.290.0060.00330.84
8.1.280.0160.00325.92
8.1.270.0090.00023.99
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0060.00320.94
8.1.230.0070.00320.88
8.1.220.0030.00517.79
8.1.210.0060.00318.85
8.1.200.0040.00417.35
8.1.190.0000.00817.35
8.1.180.0000.00818.10
8.1.170.0000.00818.54
8.1.160.0070.00019.04
8.1.150.0040.00418.80
8.1.140.0040.00418.92
8.1.130.0070.00020.16
8.1.120.0000.00717.51
8.1.110.0080.00017.49
8.1.100.0050.00317.50
8.1.90.0040.00417.48
8.1.80.0030.00517.45
8.1.70.0030.00717.41
8.1.60.0080.00417.44
8.1.50.0060.00417.46
8.1.40.0060.00617.18
8.1.30.0150.00517.48
8.1.20.0140.00617.52
8.1.10.0120.00717.43
8.1.00.0120.00617.40
8.0.300.0070.00019.63
8.0.290.0090.00016.63
8.0.280.0000.00718.34
8.0.270.0030.00316.83
8.0.260.0060.00020.21
8.0.250.0070.00017.00
8.0.240.0070.00016.95
8.0.230.0030.00316.99
8.0.220.0000.00816.80
8.0.210.0060.00416.71
8.0.200.0100.00116.45
8.0.190.0100.00016.86
8.0.180.0060.00516.87
8.0.170.0060.00416.59
8.0.160.0100.00616.72
8.0.150.0100.00516.74
8.0.140.0100.00516.74
8.0.130.0080.00715.83
8.0.120.0110.00416.75
8.0.110.0110.00316.73
8.0.100.0130.00216.69
8.0.90.0100.00616.73
8.0.80.0090.00816.71
8.0.70.0140.00216.67
8.0.60.0090.00716.67
8.0.50.0090.00616.69
8.0.30.0110.00716.85
8.0.20.0130.00517.03
8.0.10.0130.00316.83
8.0.00.0150.00416.76
7.4.330.0000.00515.55
7.4.320.0000.00616.61
7.4.300.0090.00016.46
7.4.290.0050.00516.39
7.4.280.0110.00416.45
7.4.270.0110.00516.56
7.4.260.0090.00715.63
7.4.250.0120.00516.41
7.4.240.0130.00416.49
7.4.230.0130.00516.30
7.4.220.0080.00516.51
7.4.210.0100.00816.49
7.4.200.0090.00616.49
7.4.190.0140.00316.45
7.4.180.0140.00216.55
7.4.160.0130.00316.41
7.4.150.0110.00416.43
7.4.140.0130.00416.31
7.4.130.0100.00616.41
7.4.120.0090.00716.41
7.4.110.0150.00216.40
7.4.100.0060.00916.41
7.4.90.0140.00316.29
7.4.80.0070.00816.32
7.4.70.0130.00416.36
7.4.60.0110.00516.35
7.4.50.0090.00816.30
7.4.40.0130.00516.26
7.4.30.0120.00516.39
7.4.20.0110.00616.29
7.4.10.0110.00516.22
7.4.00.0100.00416.46
7.3.330.0140.00216.02
7.3.320.0090.00715.38
7.3.310.0090.00516.07
7.3.300.0100.00416.02
7.3.290.0080.00716.02
7.3.280.0140.00415.94
7.3.270.0100.00716.14
7.3.260.0110.00616.13
7.3.250.0130.00416.00
7.3.240.0130.00416.06
7.3.230.0140.00416.02
7.3.220.0080.00815.96
7.3.210.0140.00316.00
7.3.200.0140.00316.10
7.3.190.0080.00915.94
7.3.180.0150.00516.06
7.3.170.0100.00716.05
7.3.160.0120.00616.00
7.3.150.0120.00515.96
7.3.140.0120.00516.02
7.3.130.0110.00616.02
7.3.120.0140.00215.97
7.3.110.0110.00815.74
7.3.100.0150.00215.90
7.3.90.0110.00616.20
7.3.80.0100.00815.96
7.3.70.0110.00716.02
7.3.60.0130.00416.00
7.3.50.0120.00516.15
7.3.40.0120.00616.12
7.3.30.0090.00916.04
7.3.20.0100.00616.60
7.3.10.0100.00816.60
7.3.00.0140.00416.62
7.2.340.0140.00416.01
7.2.330.0150.00316.04
7.2.320.0110.00616.15
7.2.310.0100.00615.93
7.2.300.0110.00616.18
7.2.290.0150.00216.16
7.2.280.0110.00616.12
7.2.270.0090.00915.97
7.2.260.0130.00415.97
7.2.250.0130.00616.10
7.2.240.0120.00616.03
7.2.230.0100.00716.03
7.2.220.0140.00516.01
7.2.210.0110.00615.93
7.2.200.0110.00816.24
7.2.190.0120.00416.11
7.2.180.0090.00816.09
7.2.170.0110.00616.27
7.2.160.0120.00416.19
7.2.150.0160.00516.69
7.2.140.0110.00816.67
7.2.130.0120.00716.75
7.2.120.0110.00716.81
7.2.110.0140.00516.69
7.2.100.0200.00316.78
7.2.90.0170.00116.81
7.2.80.0120.00616.60
7.2.70.0100.00816.69
7.2.60.0120.00616.70
7.2.50.0120.00616.62
7.2.40.0120.00616.76
7.2.30.0130.00516.63
7.2.20.0150.00416.68
7.2.10.0110.00616.87
7.2.00.0120.00516.78

preferences:
112.58 ms | 403 KiB | 5 Q