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 function (int $depth) use ($frequencies) { return [$depth, $frequencies[$depth]]; }, 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.0050.00216.58
8.5.00.0120.00920.14
8.4.160.0120.01122.46
8.4.150.0020.00014.05
8.4.140.0130.01017.65
8.4.130.0050.00520.52
8.4.120.0110.00924.25
8.4.110.0140.00717.76
8.4.100.0100.01118.00
8.4.90.0080.01220.34
8.4.80.0050.00619.13
8.4.70.0070.00918.95
8.4.60.0110.00220.39
8.4.50.0120.00720.45
8.4.40.0130.00617.79
8.4.30.0060.00320.54
8.4.20.0050.01417.98
8.4.10.0160.00319.21
8.3.290.0100.01120.97
8.3.280.0150.00820.11
8.3.270.0150.00716.49
8.3.260.0070.00516.67
8.3.250.0080.00719.00
8.3.240.0090.01017.04
8.3.230.0160.00216.55
8.3.220.0120.00519.04
8.3.210.0080.00616.57
8.3.200.0020.00716.74
8.3.190.0040.00417.23
8.3.180.0070.00218.66
8.3.170.0160.00317.16
8.3.160.0150.00316.92
8.3.150.0120.00616.61
8.3.140.0080.00016.62
8.3.130.0080.00018.59
8.3.120.0060.00321.02
8.3.110.0090.00020.94
8.3.100.0030.00624.06
8.3.90.0070.00326.77
8.3.80.0090.00020.26
8.3.70.0060.00916.58
8.3.60.0070.01116.75
8.3.50.0080.01524.41
8.3.40.0040.01221.89
8.3.30.0040.01118.84
8.3.20.0040.00424.18
8.3.10.0040.00424.66
8.3.00.0000.00826.16
8.2.300.0100.01022.23
8.2.290.0130.00617.40
8.2.280.0080.00118.00
8.2.270.0030.01016.98
8.2.260.0080.00017.13
8.2.250.0070.00718.92
8.2.240.0040.00417.07
8.2.230.0040.00422.58
8.2.220.0040.00437.54
8.2.210.0080.00026.77
8.2.200.0030.01016.75
8.2.190.0120.00416.88
8.2.180.0070.00725.92
8.2.170.0100.00718.98
8.2.160.0100.00322.96
8.2.150.0040.00425.66
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00426.35
8.2.110.0030.00721.12
8.2.100.0060.00618.09
8.2.90.0050.00517.75
8.2.80.0000.00818.91
8.2.70.0050.00317.93
8.2.60.0030.00618.34
8.2.50.0040.00418.10
8.2.40.0140.00019.10
8.2.30.0000.00719.21
8.2.20.0040.00418.07
8.2.10.0030.00619.39
8.2.00.0080.00019.21
8.1.330.0140.00521.86
8.1.320.0050.00515.99
8.1.310.0060.00316.76
8.1.300.0150.00318.50
8.1.290.0030.00618.88
8.1.280.0090.00925.92
8.1.270.0040.00722.13
8.1.260.0040.00428.09
8.1.250.0060.00328.09
8.1.240.0090.00019.13
8.1.230.0080.00419.19
8.1.220.0000.01018.54
8.1.210.0040.00418.77
8.1.200.0060.00317.35
8.1.190.0000.00817.35
8.1.180.0000.00818.10
8.1.170.0060.00318.43
8.1.160.0050.00519.04
8.1.150.0000.00718.91
8.1.140.0000.00818.98
8.1.130.0030.00317.39
8.1.120.0040.00417.54
8.1.110.0040.00417.40
8.1.100.0000.00817.38
8.1.90.0000.00717.36
8.1.80.0090.00017.45
8.1.70.0090.00017.48
8.1.60.0060.00317.62
8.1.50.0000.00817.54
8.1.40.0040.00417.51
8.1.30.0090.00017.68
8.1.20.0030.00617.54
8.1.10.0040.00417.57
8.1.00.0000.00817.59
8.0.300.0030.00518.77
8.0.290.0040.00416.75
8.0.280.0040.00418.39
8.0.270.0070.00016.89
8.0.260.0070.00016.84
8.0.250.0080.00016.94
8.0.240.0040.00416.86
8.0.230.0070.00016.94
8.0.220.0040.00416.93
8.0.210.0030.00516.88
8.0.200.0030.00316.96
8.0.190.0040.00416.93
8.0.180.0040.00416.77
8.0.170.0000.00916.90
8.0.160.0030.00716.97
8.0.150.0060.00316.88
8.0.140.0100.00016.79
8.0.130.0000.00613.38
8.0.120.0040.00416.78
8.0.110.0020.00516.79
8.0.100.0000.00716.74
8.0.90.0000.00716.89
8.0.80.0060.00916.87
8.0.70.0050.00216.90
8.0.60.0000.00816.72
8.0.50.0070.00016.96
8.0.30.0100.00617.08
8.0.20.0110.00817.03
8.0.10.0040.00416.88
8.0.00.0150.00916.65
7.4.330.0050.00015.55
7.4.320.0000.00716.62
7.4.300.0040.00416.63
7.4.290.0050.00316.56
7.4.280.0000.00816.65
7.4.270.0000.00716.54
7.4.260.0030.00313.29
7.4.250.0030.00616.58
7.4.240.0070.00016.54
7.4.230.0000.00716.72
7.4.220.0060.00116.71
7.4.210.0080.01016.57
7.4.200.0030.00716.44
7.4.130.0120.00716.44
7.4.120.0200.01016.62
7.4.110.0180.01216.60
7.4.100.0220.01016.35
7.4.90.0310.00016.37
7.4.80.0250.00416.57
7.4.70.0320.00716.54
7.4.60.0170.01416.59
7.4.50.0240.00316.64
7.4.40.0200.01016.50
7.4.30.0230.00916.39
7.4.20.0180.00415.84
7.4.10.0100.01316.23
7.4.00.0030.01616.65
7.3.330.0000.00716.40
7.3.320.0060.00013.21
7.3.310.0000.00716.25
7.3.300.0030.00316.38
7.3.290.0070.00816.41
7.3.260.0200.01316.55
7.3.240.0000.01716.45
7.3.230.0170.01416.39
7.3.220.0250.01316.71
7.3.210.0290.00316.46
7.3.200.0260.00616.52
7.3.190.0240.00816.40
7.3.180.0260.00816.66
7.3.170.0210.00916.31
7.3.160.0250.00616.43
7.3.150.0100.00616.51
7.3.140.0150.00816.17
7.3.130.0090.01216.33
7.3.120.0120.01216.13
7.3.110.0120.01615.98
7.3.100.0030.02116.07
7.3.90.0110.01116.30
7.3.80.0110.01816.20
7.3.70.0180.00616.36
7.3.60.0140.00916.41
7.3.50.0190.00416.53
7.3.40.0040.02116.50
7.3.30.0120.01216.45
7.3.20.0100.01516.61
7.3.10.0130.00816.39
7.3.00.0390.00016.41
7.2.340.0210.01116.58
7.2.330.0240.00616.75
7.2.320.0230.00816.80
7.2.310.0220.00716.82
7.2.300.0230.00816.66
7.2.290.0280.00616.78
7.2.280.0000.01616.58
7.2.270.0030.01716.62
7.2.260.0140.01116.21
7.2.250.0110.01516.09
7.2.240.0160.01116.08
7.2.230.0090.01716.33
7.2.220.0120.01216.66
7.2.210.0110.01116.69
7.2.200.0060.01716.62
7.2.190.0070.01416.73
7.2.180.0090.01616.88
7.2.170.0150.01116.73
7.2.160.0150.00916.58
7.2.150.0080.01616.54
7.2.140.0290.01216.78
7.2.130.0320.00516.71
7.2.120.0340.00616.66
7.2.110.0330.00716.66
7.2.100.0270.01116.77
7.2.90.0130.01316.72
7.2.80.0130.01016.75
7.2.70.0120.00916.53
7.2.60.0170.00616.56
7.2.50.0150.00316.82
7.2.40.0070.01116.58
7.2.30.0100.01016.83
7.2.20.0150.00916.60
7.2.10.0130.00616.68
7.2.00.0100.00916.52

preferences:
178.62 ms | 403 KiB | 5 Q