Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit:</strong></p> <p>Assuming the array you've updated to is called $table:</p> <pre><code>// $S is array for S where sums are stored $S = array(); $S[0] = $table[0][v] - $table[0][p]; // Perform the first row for ($i=1; $i&lt; count($table); $i++) { // Start at 2nd and continue on $S[$i] = $S[($i-1)] + ($table[$i][v] - $table[$i][p]); } </code></pre> <p>Now all the $S values are populated as such. If you want to add to the table:</p> <pre><code>$table[0][s] = $table[0][v] - $table[0][p]; // Perform the first row for ($i=1; $i&lt; count($table); $i++) { // Start at 2nd and continue on $table[$i][s] = $table[$i-1][s] + ($table[$i][v] - $table[$i][p]); } </code></pre> <hr> <p>Yes you can, considering you want the S values of 1, 2, 3 ... then yes. I assume V is an array and P is an array so you'll have to change accordingly, since each S can be based off the previous, I keep a running_sum value so that we don't have to iterate over previous values of V and P, we just use the last value of S:</p> <pre><code>// $V is array for V and $P is array for P and // $S is array for S where sums are stored if (count($V) == count($P)) { // Check both V and P are same length $running_sum = 0; for ($i=0; $i&lt; count($V); $i++) { $running_sum += ($V[$i] - $P[$i]); $S[$i] = $running_sum; } } </code></pre> <p>We really don't need the running sum variable though but I used it to make the logic clear, here it is without it:</p> <pre><code>// $V is array for V and $P is array for P and // $S is array for S where sums are stored if (count($V) == count($P)) { // Check both V and P are same length $S[0] = $V[0] - $P[0]; // Perform the first row for ($i=1; $i&lt; count($V); $i++) { // Start at 2nd and continue on $S[$i] = $S[($i-1)] + ($V[$i] - $P[$i]); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload