**
* Returns the word with the most consecutive Consonants.
*
* Find and return the word with the most consecutive consonants in a sentence.
* If more than 1 is found, print only the first.
*
* @param string $sentence The sentence
`
<?php
function returnTheWordWithTheMostConsecutiveConsonants(string $sentence)
{
$sentence = ['a','e','i','o','y','A','E','I','O','Y'];
return !$sentence;
}
function testAndValidateEach(array $sentences)
{
$max = -1;
$countConsonne = 0;
$i = 0;
while($i < count($sentences)) {
while(returnTheWordWithTheMostConsecutiveConsonants($sentences[$i])) {
$countConsonne++;
$i++;
}
if ($countConsonne > $max && $countConsonne != -1) {
$max = $countConsonne;
} else {
$countConsonne = 0;
}
$i++;
}
return $max;
}
echo testAndValidateEach($sentences);
source https://stackoverflow.com/questions/70137129/find-the-longest-word-with-consecutive-consonants-in-php
Comments
Post a Comment