I came across some sample PHP code, and can’t figure out the syntax. It’s a function that calculates what percentage of a given string is made up of vowels. Ie, “motion” would return a value of [B]50%
[code=php]
function percentVowels_callback($word) {
$word = strtolower($word);
$chars = count_chars($word);
$numVowels = 0;
foreach (array(“a”, “e”, “i”, “o”, “u”) as $vowel) {
$numVowels += $chars[ord($vowel)];
}
return $numVowels / strlen($word);
}
Specifically, what is THIS bit:
[code=php] $numVowels += $chars[ord($vowel)];
Obviously [B]$numVowels[b]$chars[ord($vowel)]
Remembering that [b]$chars
[code=php]$numVowels += $chars[ord(‘a’)]
$numVowels += $chars[ord(‘e’)]
$numVowels += $chars[ord(‘i’)]
$numVowels += $chars[ord(‘o’)]
$numVowels += $chars[ord(‘u’)]
Let’s say [B]$chars
[code=php]$numVowels += 7[ord(‘a’)]
$numVowels += 7[ord(‘e’)]
$numVowels += 7[ord(‘i’)]
$numVowels += 7[ord(‘o’)]
$numVowels += 7[ord(‘u’)]
What on earth is going on? I have never seen PHP code that looks like that.