PHP array question
<p>I have a array called $A which contains only non zero positive numbers. </p>

<p>Now I need to find any number of distinct consecutive subarrays that have a given sum.</p>

<p>I will explain with example</p>

<pre><code>$A = array(1,2,3,4,5);
</code></pre>

<p>and the sum I am looking for is <code>5</code>.</p>

<p>Then there are <code>(2, 3)</code> and <code>(5)</code>.</p>

<p>I tried searching and got a python code. I've translated it to PHP below but it refuses to work</p>

<pre><code>$s = 0;
for($i = 0; $i &lt; count($A); $i++){
     for($j=$i; $j &lt; count($A); $j++){
         $s = $s + $A[$j];
         if($s == $sum) {
             echo "[" . $i . " " . $j . "]";
         }
     }
}
</code></pre>

<p>Please help.</p>
