How to find an integer which is cummulative and get the intial value in the row instead of the total value?
<p>I have a table as below:</p>

<pre><code>Date            id  r1   r2
2/1/2013 13:00  829 574 630
2/1/2013 13:00  829 39  10169
2/1/2013 7:00   829 597 37206
2/1/2013 13:00  829 532 29
2/1/2013 7:00   829 596 50881
2/1/2013 13:00  829 509 38
2/1/2013 7:00   829 595 48053
2/1/2013 13:00  829 481 3573
2/1/2013 7:00   829 594 266
2/1/2013 13:00  829 421 76064
2/1/2013 7:00   829 593 289
2/1/2013 7:00   829 576 5
2/1/2013 7:00   829 575 162
</code></pre>

<p>Now in the above row r1 and r2, i would like to find which rows have cumulative integer and replace it to the same cumulative integer.
Example:
    cumulative series: 2 4 6 8 10 12 14 16 18 20 
    cumulative integer: 2
    Total cumulative sum: 20</p>

<p>In my case function should return output to 2 (cumulative integer) and output 2 can be achieved only if we recursively go in depth of series.</p>

<p>e.g. In the above table, first row r1 value is 574, where i know only the sum. </p>

<p>x0+x1+x2+x3+x4+x5+..... = 574</p>

<p>Now, how i can find the value of first x0?</p>

<p>Can somebody please advice how i can achieve this in PHP function?</p>
