title: Loop through array elements and substract values if keys are the same
body: <p>I am looping through two arrays called $result_start and $result_end arrays.</p>
  
  <p>There are 2 cases here: </p>
  
  <p>1) If arrays have same keys -> substract values (no problem here)</p>
  
  <p>Let's say: </p>
  
  <pre><code>$result_start[18]['fld_IndActive1Imp'] = 100;
  $result_start[5]['fld_IndActive1Imp'] = 100;
  
  $result_end[18]['fld_IndActive1Imp'] = 250;
  $result_end[5]['fld_IndActive1Imp'] = 300;
  </code></pre>
  
  <p>So values should be </p>
  
  <pre><code>$consumptions[0] =&gt; 150  // result_end - result_start (for key #18)
  $consumptions[1] =&gt; 200 // result_end - result_start (for key #5)
  </code></pre>
  
  <p>In this case the code I wrote is below and works fine:</p>
  
  <pre><code>if (!array_diff_key($result_start, $result_end) &amp;&amp; !array_diff_key($result_end, $result_start)) {
          for ($index = 0; $index &lt; count($result_start); $index++) {
              $consumptions[$index]['active1_imp'] = $result_end[$index]['fld_IndActive1Imp'] - $result_start[$index]['fld_IndActive1Imp'];
          }
  }
  </code></pre>
  
  <p>2) If 1 array have more keys then the other (having problems)</p>
  
  <p>For example let's say arrays an values are like below:</p>
  
  <pre><code>$result_start[18]['fld_IndActive1Imp'] = 100;
  $result_start[5]['fld_IndActive1Imp'] = 100;
  
  $result_end[5]['fld_IndActive1Imp'] = 300;
  </code></pre>
  
  <p>In this case, consumptions should be,</p>
  
  <pre><code>$consumptions[0] =&gt; 0 // // No end value for key #18 so it's 0
  $consumptions[1] =&gt; 200 // result_end - result_start (for key #5)
  </code></pre>
  
  <p>I'm having problems writing second case. Any tips?</p>