[Opgelost] Vowels Count - PHP Function Task

  

2
Onderwerp starter

Write a function that receives a single string and prints the count of the vowels. Use appropriate name for the function.

Examples:

vowels count php function task

1 antwoord
2

Here is my answer:

<?php
 
$word = readline();
 
echo countVowels($word);
 
function countVowels($input) {
    $count = 0;
    for ($i = 0; $i < strlen($input); $i++) {
        $current = strtolower($input[$i]);
        if ($current == "a" || $current == "u" || $current == "i" || $current == "e" || $current == "o") {
            $count++;
        }
    }
    return $count;
}
Deel: