title: how to order in while loop?
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>9 // count of 'I am John'
  4 // count of 'I am'
  1 // count of 'I'
  </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){
      if($i==0) {
      $words_length[$i] = strlen($words[$i]);
      } else {
      $words_length[$i] = strlen($words[$i])+1+$words_length[$i-1];
      }
      echo $words_length[$i]."&lt;br&gt;";
      $i++;
  }
  </code></pre>
  
  <p>But it return the output like this:</p>
  
  <pre><code>1
  4
  9
  </code></pre>
  
  <p>Why ? Where is my error ? How can I change the ordering ?<br/> What does my code must be like ?<br/>
  Thanks in advance!</p>