How to use Conditional Statements In PHP
The simplest way to check if a given letter is a vowel or consonant is by using conditional statements. This approach is straightforward to understand for beginners.
Example:
PHP
<?php function isVowel( $letter ) { $letter = strtolower ( $letter ); if ( $letter == "a" || $letter == "e" || $letter == "i" || $letter == "o" || $letter == "u" ) { return true; } else { return false; } } // Driver code $letter = "E" ; if (isVowel( $letter )) { echo "$letter is a vowel." ; } else { echo "$letter is a consonant." ; } ?> |
E is a vowel.
PHP Program to Check if a Given Letter is Vowel or Consonant
Determining whether a given letter is a vowel or consonant is a fundamental programming task that can be approached in various ways using PHP. This article explores multiple methods to achieve this, catering to beginners and experienced developers alike.