How can I check if a string is a multi word sentence or just a single word?
I tried by splitting by a space so if it is one word, there will be only one word in the array and if there is more, then they will all be in the array.
But, when I try to split by a space and run through that array, I am getting no output.
Here is the code:
$input = "the quick brown fox jumped over the lazy dog";
$sentence = explode(" ", $input);
foreach($sentence as $item){
echo $item;
}
The above is giving me no output.
So, I have 2 questions:
- How can I detect if a string is composed of multiple words in an if statement?
- Why isn't my above code splitting the sentence into an array with the words?
" "
.