Advertisement
Yousuf1791

Vowel and Consonent

Nov 30th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. //Vowel and Consonent
  2. <?php
  3. $string = "Yousuf";
  4.  
  5. $first_char = array(substr($string, 0,1));
  6. // echo "<pre>";
  7.  
  8. // print_r($first_char);
  9.  
  10. $a1 = array(
  11. "a", "e", "i", "o", "u",
  12. "A", "E", "I", "O", "U",
  13. );
  14.  
  15. $a2 = array(
  16. "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z",
  17. "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z"
  18. );
  19.  
  20. $vowel = array_intersect($first_char, $a1);// array_interstct() = matching a specic value
  21. $consonent = array_intersect($first_char, $a2);
  22.  
  23. // echo "<pre>";
  24.  
  25. // print_r($vowel);
  26.  
  27. if ($first_char == $vowel) {
  28. echo "The string is vowel";
  29. }elseif ($first_char == $consonent) {
  30. echo "The string is consonent";
  31. }else{
  32. echo "The input is not a string";
  33. }
  34.  
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement