February 27, 2013
Split words starting with vowels and consonants to arrays
Question by user2116493
i have to make a script in PHP. First in splits the sentence by spaces and adds to array. Then it splits the words from array by the starting letter. If it starts with vowel, it goes into one array and if it starts with consonant, it goes to other arrray. Then it prints the words with the both arrays and shows the number of letters in the word by every word.
Allowed functsions are explode, strlen, in_array.
Thank you.
Answer by Starx
You can start by using explode()
function.
$sentence = "Your long long sentence";
$explodeIntoWords = explode(" ", $sentence); //You can specify the sentence to be split based on words.
//Now you can loop through this array and compare them if they are vowels or consonants
foreach($explodeIntoWords as $value) {
// Analyse $value
}