Check whether a character is vowel or consonant in php
Check whether a character is vowel or consonant
Following is sample php code.
<?php
// Check whether a character is vowel or consonant
function checkIsVowelOrConstant($char = null) {
if (empty($char)) {
return 'Please provide input.';
}
if (strlen($char) != 1) {
return "Please provide a single character.";
}
if (in_array($char, ['a', 'e', 'i', 'o', 'u'])) {
return "Given character is vowel";
}
return "Given character is consonant";
}
echo checkIsVowelOrConstant('f');
?>