3v4l.org

run code in 500+ PHP versions simultaneously
<?php function detectLanguage(array $langs, string $header): ?string { $s = strtolower($header); // case insensitive $s = strtr($s, '_', '-'); // cs_CZ means cs-CZ rsort($langs); // first more specific preg_match_all('#(' . implode('|', $langs) . ')(?:-[^\s,;=]+)?\s*(?:;\s*q=([0-9.]+))?#', $s, $matches); if (!$matches[0]) { return null; } $max = 0; $lang = null; foreach ($matches[1] as $key => $value) { $q = $matches[2][$key] === '' ? 1.0 : (float) $matches[2][$key]; if ($q > $max) { $max = $q; $lang = $value; } } return $lang; } echo detectLanguage(['en', 'fr', 'zn'], 'cs,en;q=0.9,fr;q=0.8,zh-CN;q=0.7,zh;q=0.6');

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.30.0100.00718.17
8.5.20.0130.00520.32
8.5.10.0110.00716.82
8.5.00.0120.01019.93
8.4.180.0120.01219.75
8.4.170.0110.01223.93
8.4.160.0150.00722.01
8.4.150.0090.00416.98
8.4.140.0100.01218.02
8.4.130.0140.00618.79
8.4.120.0110.00824.36
8.4.110.0060.00422.39
8.4.100.0130.00817.60
8.4.90.0280.00617.84
8.4.80.0160.00417.93
8.4.70.0120.01017.82
8.4.60.0160.00317.59
8.4.50.0140.00717.78
8.4.40.0200.00417.63
8.4.30.0210.00117.70
8.4.20.0150.00517.72
8.4.10.0190.00417.64
8.3.300.0120.01020.85
8.3.290.0100.01020.71
8.3.280.0150.00818.60
8.3.270.0140.00516.70
8.3.260.0090.00916.63
8.3.250.0140.00418.75
8.3.240.0170.00616.66
8.3.230.0160.00316.67
8.3.220.0160.00316.72
8.3.210.0180.00416.29
8.3.200.0160.00916.79
8.3.190.0170.00316.62
8.3.180.0210.00216.75
8.3.170.0210.00216.38
8.3.160.0220.00216.60
8.3.150.0170.00516.29
8.3.140.0180.00416.47
8.3.130.0150.00516.39
8.3.120.0180.00216.85
8.3.110.0190.00116.54
8.3.100.0170.00416.39
8.3.90.0170.00516.27
8.3.80.0160.00516.81
8.3.70.0170.00516.47
8.3.60.0160.00516.52
8.3.50.0140.00616.63
8.3.40.0180.00317.47
8.3.30.0140.00417.57
8.3.20.0120.00617.54
8.3.10.0130.00617.46
8.3.00.0070.00517.36
8.2.300.0130.00820.39
8.2.290.0050.00416.82
8.2.280.0110.00516.91
8.2.270.0140.00416.26
8.2.260.0140.00516.62
8.2.250.0150.00316.59
8.2.240.0170.00116.85
8.2.230.0180.00116.41
8.2.220.0140.00516.85
8.2.210.0130.00516.83
8.2.200.0140.00516.39
8.2.190.0170.00816.80
8.2.180.0180.00416.83
8.2.170.0180.00317.50
8.2.160.0130.00417.94
8.2.150.0140.00417.77
8.2.140.0160.00417.55
8.2.130.0160.00317.71
8.2.120.0160.00417.70
8.2.110.0160.00517.68
8.2.100.0160.00217.58
8.2.90.0170.00317.74
8.2.80.0130.00517.61
8.2.70.0130.00617.62
8.2.60.0170.00317.53
8.2.50.0120.00817.68
8.2.40.0120.00617.67
8.2.30.0170.00617.64
8.2.20.0140.00217.46
8.2.10.0130.00417.69
8.2.00.0140.00317.59
8.1.340.0110.00921.90

preferences:
44.88 ms | 831 KiB | 5 Q