3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StringUtil{ /** * Returns the English plural of the given phrase based on the value. * Note, there are certainly exceptions and if someone wants to white/black-list them, go ahead. * Some exceptions that do not work with this function noted by mickmackusa: * appendix, axis, fungus, deer, child, syllabus, louse, person, goose, bacterium * @see first version: https://3v4l.org/VJni0 * @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 $singularPhrase, float|int|array|object $value): string{ if ($value === 1){ return $singularPhrase; } if (is_countable($value)){ if (count($value) === 1){ return $singularPhrase; } }else if (is_object($value)){ //object that does not implement Countable return $singularPhrase; } //If the string doesn't even end with a letter, just return the phrase. if (!preg_match('/[a-zA-Z]$/', $singularPhrase)){ return $singularPhrase; } if (str_ends_with($singularPhrase, 'y')){ return substr($singularPhrase, 0, -1).'ies'; } //In English, words that end with these characters, you add "es" to make them plural. $es_append = ['x','z','s','ch','sh']; foreach($es_append as $end){ if (str_ends_with($singularPhrase, $end)){ return $singularPhrase.'es'; } } //It didn't fit any of the above criteria, so just add "s" return $singularPhrase.'s'; } } $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.0090.01219.74
8.4.120.0080.00420.84
8.4.110.0070.00522.24
8.4.100.0120.01018.76
8.4.90.0080.00219.07
8.4.80.0110.00820.57
8.4.70.0050.00418.07
8.4.60.0110.01119.00
8.4.50.0140.00618.75
8.4.40.0100.01017.58
8.4.30.0060.00319.09
8.4.20.0160.00318.10
8.4.10.0100.01019.73
8.3.260.0100.01016.72
8.3.250.0050.00419.04
8.3.240.0140.00617.27
8.3.230.0120.00716.66
8.3.220.0090.00618.86
8.3.210.0050.00318.41
8.3.200.0060.00316.65
8.3.190.0100.00816.76
8.3.180.0080.00916.77
8.3.170.0130.00619.01
8.3.160.0140.00317.17
8.3.150.0140.00417.17
8.3.140.0050.00320.90
8.3.130.0040.00418.57
8.3.120.0100.00018.92
8.3.110.0080.00020.94
8.3.100.0070.00316.44
8.3.90.0060.00926.77
8.3.80.0030.00618.68
8.3.70.0070.01116.63
8.3.60.0110.00616.63
8.3.50.0220.00018.42
8.3.40.0110.00422.09
8.3.30.0130.01022.96
8.3.20.0170.00323.56
8.3.10.0100.01022.96
8.3.00.0140.00722.96
8.2.290.0110.00720.82
8.2.280.0120.00618.48
8.2.270.0120.00618.98
8.2.260.0080.00816.83
8.2.250.0150.00016.60
8.2.240.0080.00018.99
8.2.230.0110.00822.58
8.2.220.0060.00324.06
8.2.210.0100.01026.77
8.2.200.0090.00016.63
8.2.190.0160.00718.79
8.2.180.0060.00916.63
8.2.170.0140.00422.96
8.2.160.0140.00422.96
8.2.150.0110.00722.96
8.2.140.0060.01422.96
8.2.130.0200.00022.96
8.2.120.0150.00422.96
8.2.110.0090.00922.96
8.2.100.0110.00722.96
8.2.90.0150.00622.96
8.2.80.0080.00822.96
8.2.70.0120.00922.96
8.2.60.0090.00622.96
8.2.50.0100.01022.96
8.2.40.0160.00022.96
8.2.30.0150.00622.96
8.2.20.0030.01722.96
8.2.10.0090.01222.96
8.2.00.0140.00722.96
8.1.330.0090.01022.02
8.1.320.0110.00916.71
8.1.310.0100.00318.33
8.1.300.0050.00519.71
8.1.290.0060.00330.84
8.1.280.0170.00325.92
8.1.270.0070.01122.96
8.1.260.0140.00322.96
8.1.250.0060.01122.96
8.1.240.0060.01222.96
8.1.230.0070.01122.96
8.1.220.0090.00922.96
8.1.210.0100.01022.96
8.1.200.0070.01422.96
8.1.190.0080.01122.96
8.1.180.0150.00422.96
8.1.170.0090.00622.96
8.1.160.0040.01822.96
8.1.150.0130.00722.96
8.1.140.0110.01122.96
8.1.130.0070.00722.96
8.1.120.0110.00422.96
8.1.110.0140.00022.96
8.1.100.0080.00622.96
8.1.90.0130.00622.96
8.1.80.0090.00622.96
8.1.70.0040.01422.96
8.1.60.0130.00622.96
8.1.50.0070.00722.96
8.1.40.0040.01122.96
8.1.30.0070.00722.96
8.1.20.0070.00722.96
8.1.10.0070.00722.96
8.1.00.0070.00722.96

preferences:
27.57 ms | 403 KiB | 5 Q