3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StringUtil{ /** * Returns the English plural of the given phrase based on the value. * * @see https://stackoverflow.com/a/34254595/1993494 (idea from this) * @param string $phrase The phrase to determine the plural form * @param float|int|array|object $value The value to determine whether the phrase should be plural or not * @return string The English plural form of the phrase based on the value */ public static function pluralEnglish(string $phrase, float|int|array|object $value): string{ if (empty($phrase) || is_numeric($phrase)){ return $phrase; } if (is_object($value) || is_array($value)){ $val = count($value); }else{ $val = $value; } if ($val == 1){ return $phrase; } //since the value is not singular, it is plural, so we need to come up with the english plural. $last = substr($phrase, -1); $last2 = substr($phrase, -2); $replace = false; $append = false; switch($last){ case 'x': case 'z': case 's': $append = 'es'; break; case 'y': $replace = 'ies'; break; default: switch($last2){ case 'ch': case 'sh': $append = 'es'; break; default: $append = 's'; } } if ($append) { return $phrase . $append; }else if ($replace){ return substr($phrase, 0, -1) . $replace; }else{ return $phrase; } } } $ary = [ 'kibitz', 'miss', 'fox', 'box', 'item', 'god', 'fun', 'diety', 'touch', 'teach', 'watch', 'test', 'fire', ]; $count = 0; foreach($ary as $phrase){ echo StringUtil::pluralEnglish($phrase, $count)."\n"; }

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.0060.01117.51
8.4.120.0110.00720.55
8.4.110.0110.00918.80
8.4.100.0060.00217.75
8.4.90.0140.00718.87
8.4.80.0100.00717.89
8.4.70.0140.00617.99
8.4.60.0130.00618.86
8.4.50.0090.00819.54
8.4.40.0070.01317.70
8.4.30.0180.00018.83
8.4.20.0120.00417.61
8.4.10.0030.01619.50
8.3.260.0140.00516.43
8.3.250.0080.01019.05
8.3.240.0100.00816.55
8.3.230.0100.00916.51
8.3.220.0080.01017.20
8.3.210.0120.00616.41
8.3.200.0030.00616.73
8.3.190.0090.00917.04
8.3.180.0150.00516.64
8.3.170.0040.01518.96
8.3.160.0070.01117.09
8.3.150.0110.00717.34
8.3.140.0080.00816.48
8.3.130.0000.01116.72
8.3.120.0110.00020.75
8.3.110.0190.00018.10
8.3.100.0000.00816.48
8.3.90.0040.00426.77
8.3.80.0040.00718.53
8.3.70.0070.00718.30
8.3.60.0060.01216.50
8.3.50.0110.01118.66
8.3.40.0130.00721.86
8.3.30.0100.00718.67
8.3.20.0120.00321.60
8.3.10.0030.01021.70
8.3.00.0120.00318.91
8.2.290.0100.00720.65
8.2.280.0120.00818.13
8.2.270.0000.00817.16
8.2.260.0080.00016.46
8.2.250.0000.00816.68
8.2.240.0050.00317.20
8.2.230.0080.00020.94
8.2.220.0060.00316.73
8.2.210.0110.00726.77
8.2.200.0030.00618.16
8.2.190.0140.00718.38
8.2.180.0100.01016.50
8.2.170.0090.00619.14
8.2.160.0040.01118.96
8.2.150.0120.00319.28
8.2.140.0100.00620.49
8.2.130.0090.00620.40
8.2.120.0030.01219.22
8.2.110.0070.00719.35
8.2.100.0070.00719.07
8.2.90.0150.00018.82
8.2.80.0140.00019.16
8.2.70.0060.00918.70
8.2.60.0120.00618.58
8.2.50.0140.00318.97
8.2.40.0110.00718.60
8.2.30.0070.01018.64
8.2.20.0130.00318.57
8.2.10.0040.01118.71
8.2.00.0090.00618.64
8.1.330.0030.00521.80
8.1.320.0080.01116.16
8.1.310.0050.00318.54
8.1.300.0110.00016.80
8.1.290.0060.00630.84
8.1.280.0070.00725.92
8.1.270.0110.00421.98
8.1.260.0120.00322.07
8.1.250.0100.00722.11
8.1.240.0080.00818.43
8.1.230.0120.00318.59
8.1.220.0140.00018.82
8.1.210.0030.01318.38
8.1.200.0120.00318.71
8.1.190.0060.00918.68
8.1.180.0080.00818.34
8.1.170.0090.00618.74
8.1.160.0090.00918.27
8.1.150.0090.00918.87
8.1.140.0130.00318.66
8.1.130.0060.00918.57
8.1.120.0070.01118.63
8.1.110.0060.00918.63
8.1.100.0120.00619.56
8.1.90.0130.00618.51
8.1.80.0160.00319.73
8.1.70.0140.00418.68
8.1.60.0060.00918.80
8.1.50.0160.00018.54
8.1.40.0080.00818.73
8.1.30.0100.00618.91
8.1.20.0100.00719.83
8.1.10.0130.00318.62
8.1.00.0090.00618.51

preferences:
50.25 ms | 403 KiB | 5 Q