-
-
Save jamescridland/837874 to your computer and use it in GitHub Desktop.
A little bit of PHP to return "a" and "an" correctly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// Usage: | |
echo "I have ".return_indefinitearticle("apple")." apple, and ".return_indefinitearticle("slice of bread")." slice of bread."; | |
function return_indefinitearticle($thing) { | |
return (preg_match('/^[aeiou]|s\z/i', strtolower($thing))) ? "an" : "a"; | |
} | |
?> |
Here's the answer..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, no..
[PASS] apple ............... Result: an .... Expected: an
[PASS] dog ................. Result: a .... Expected: a
[PASS] house ............... Result: a .... Expected: a
[FAIL] hour ................ Result: a .... Expected: an
[FAIL] university .......... Result: an .... Expected: a
[PASS] yellow dog .......... Result: a .... Expected: a
[FAIL] ytterbium molecule .. Result: a .... Expected: an
[FAIL] U ................... Result: an .... Expected: a
[FAIL] M ................... Result: a .... Expected: an
[PASS] umbrella ............ Result: an .... Expected: an