title: Get win/loss streak from an array in PHP
body: <p>With the following code, I analyze all the games that a team has played yet and create an array with the results:</p>
  
  <pre><code>public function getResults($id) {
      $array = array();
      $scores = $this -&gt; getAvailableScoresForTeam($id);
      for ($i = 0; $i &lt; count($scores); $i++) {
          $homeTeam = $scores[$i]['homeTeam'];
          $awayTeam = $scores[$i]['awayTeam'];
          $homeScore = $scores[$i]['homeScore'];
          $awayScore = $scores[$i]['awayScore'];
  
          if ($homeTeam == $id &amp;&amp; $homeScore &gt; $awayScore) {
              $array[$i] = "W";
          }
          elseif ($awayTeam == $id &amp;&amp; $awayScore &gt; $homeScore) {
              $array[$i] = "W";
          }
          elseif ($homeTeam == $id &amp;&amp; $homeScore &lt; $awayScore) {
              $array[$i] = "L";
          }
          elseif ($awayTeam == $id &amp;&amp; $awayScore &lt; $homeScore) {
              $array[$i] = "L";
          }
      }
      return $array;
  }
  </code></pre>
  
  <p>For example, if the team 1 played 4 total games, lost the first one and won the last 3, then the array for team 1 would be: <code>(L, W, W, W)</code></p>
  
  <p>What I am having trouble with is determining the win/loss streak. With the array above, I need to analyze the last couple of elements and see if they were losses ("L") or wins ("W") and if so, then how many.</p>
  
  <p>For the output, I am only trying to get the most recent one. So for <code>(L, W, W, L, W, W)</code>, it should be 2 wins since the last two games were won and the one before that wasn't.</p>