counting strings in foreach

Hello,
I have a string that divide it into pieces with a comma.
Each piece divide it into smaller interval with.
You have to count how many pieces with interval there are in every piece with comma below.

$string = "1str 1str, 2str 2str, 3str 3str";
$keywords = explode(',', $string);
foreach ($keywords as $v) {
    $parts = explode(' ', $v);
    echo count($parts) . "<br>";
}

Code (markup):
Outputs the 2 3 3, not what it expect 2 2 2
Where is the problem?
Why counting does not work properly?...

counting strings in foreach

from PHP http://ift.tt/1Ofc1dD
via IFTTT
Previous
Next Post »
Thanks for your comment