counting strings in foreach

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) . "
"; } 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

Poster :