title: Cumulative array
body: <p>I have this array:</p>
  
  <pre><code>$a = array(1, 2, 3, 4, 5, 7, 8, 10, 12);
  </code></pre>
  
  <p>Is there a function to convert this to:</p>
  
  <pre><code>$b = array(1, 1, 1, 1, 2, 1, 2, 2);
  </code></pre>
  
  <p>So basicaly:</p>
  
  <pre><code>$b = array ($a[1]-$a[0], $a[2]-$a[1], $a[3]-$a[2], ... ,$a[n]-$a[n-1]);
  </code></pre>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>$a = $c = array(1, 2, 3, 4, 5, 7, 8, 10, 12);
  array_shift($c);
  $d = array();
  foreach ($a as $key =&gt; $value){
     $d[$key] = $c[$key]-$value;
  }
  array_pop($d);
  </code></pre>