title: PHP: Number of consecutive elements in array
body: <p>I have been working on one problem: </p>
  
  <p>Find the largest group of consecutive numbers in an array. </p>
  
  <p>Say we have an array <code>[5, 43, 4, 56, 3, 2, 44, 57, 58, 1]</code>, the biggest group of consecutive numbers in this array is 5 (1, 2, 3, 4, and 5). </p>
  
  <p>The solution algorithm must be time complexity of O(n). </p>
  
  <p>I have solved this with the following ruby code but I am having trouble porting it to PHP as the solution requires.</p>
  
  <pre><code>arr = [8, 13, 14, 10, 6, 7, 8, 14, 5, 3, 5, 2, 6, 7, 4]
  result = []
  stage = []
  for i in arr:
      if len(stage) &gt; 0 and i != stage[-1]+1:
          if len(stage) &gt; 1:
              result.append(stage)
          stage = []
      stage.append(i)
  print result
  </code></pre>