title: doesn't while loop work correctly in PHP?
body: <p>I want to get  the count of characters from the following words in the string. For example, if my input is <code>I am John</code> then the output must be like this: <br/></p>
  
  <pre><code>1 // count of 'I'
  4 // count of 'I am'
  9 // count of 'I am John'
  </code></pre>
  
  <p>I use the code like this in PHP for this process:</p>
  
  <pre><code>$string = 'I am John';
  $words = explode(' ',$string);
  $count_words = count($words);
  
  $i =0;
  while ($i&lt;=$count_words){
      $word_length =0;
      $k=0;
      while($k&lt;=$i){
          $word_length = strlen($words[$k-1]);
          $word_length = $word_length + strlen($words[$k]);
          $k++;
      }
      $word_length = $word_length + $i; // there is "$i" means "space"
      echo $word_length.'&lt;br/&gt;';
      $i++;
  
  }
  </code></pre>
  
  <p>But it return the output like this:</p>
  
  <pre><code>1
  4
  8
  7
  </code></pre>
  
  <p>Why ? Where is my error ? What does my code must be like ?<br/>
  Thanks in advance!</p>