![]() |
VOOZH | about |
There are a total of 26 letters in the English alphabet. There are 5 vowel letters and 21 consonant letters. The 5 vowel letters are: "a", "e", "i", "o", and "u" rest are consonants. There are different approaches to checking whether a character is a vowel or a consonant.
These are the different Approaches to Check Whether a Character is a Vowel or Consonant:
Table of Content
This approach uses a series of if-else statements to check if the given character is a vowel. We first convert the character to lowercase to handle both uppercase and lowercase inputs consistently. Then, we compare the character against each vowel (a, e, i, o, u). If the character matches any of these, it is a vowel otherwise it is consonant.
Example: This example shows the use of an if-else statement to Check Whether a Character is a Vowel or Consonant.
e is a vowel E is a vowel
In this method, we utilize PHP's in_array function, which checks if a value exists in an array. We create an array containing all the vowels. Then, we use in_array to check if the character is in the array of vowels. If it is, we identify it as a vowel, otherwise, it's a consonant.
Example: This example shows the use of in_array() function to Check Whether a Character is a Vowel or Consonant.
e is a vowel E is a vowel
This approach uses a switch statement to evaluate the character. We first convert the character to lowercase. The switch statement then checks if the character matches any of the cases for vowels (a, e, i, o, u). If a match is found, it is labeled as a vowel, otherwise, the default case classifies it as a consonant.
Example: This example shows the use of switch statement to Check Whether a Character is a Vowel or Consonant.
e is a vowel E is a vowel