My code is below.
1) I needed to get the number of words in each message in the message array and display it in a new array
2) If the number of words in each message was less than 5 I am supposed to add the words "smaller" to another new array and if the number of words in each message is greater than 5 I an supposed to add the string"bigger" to this same new array.
I am unsure of how to put this "bigger" and "smaller" into a new array. Please advise.(refer question 2)
$messages = array(
"Learning PHP is fun",
"I want to learn more",
"Girls can code too",
"Goodbye boredom!",
"Coding Geek",
"Computers can sometimes freeze up",
"Follow me now", "Coding is cool",
"Computer nerds are for real",
"This is the end of all the messages"
);
/* (1) */
for ($i = 0; $i < 10; $i++) {
$words[] = str_word_count($messages[$i]);
}
print_r($words);
echo "<br>";
/* (2) */
for ($i = 0; $i < 10; $i++) {
if ($words[$i] <= 5) {
$size[] = $words[$i];
echo "smaller" . "<br>";
} else {
$size[] = $words[$i];
echo"bigger";
}
}