title: Check for array value change during foreach loop php
body: <p>I'm exporting from MySQL into an Excel spreadsheet, the export works fine however I'm trying to change how the output works from the array.</p>
  
  <p>Example of the array</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [Product] =&gt; ABYT8
          [Invoice Date] =&gt; 24/04/2018
          [Carriage] =&gt; 31.00
          [Carriage Tax Code] =&gt; T0
          [Order Number] =&gt; 223
      )
  
  [1] =&gt; Array
      (
          [Product] =&gt; CASTSRF
          [Invoice Date] =&gt; 24/04/2018
          [Carriage] =&gt; 0.00
          [Carriage Tax Code] =&gt; T1
          [Order Number] =&gt; 224
      )
  
  [2] =&gt; Array
      (
          [Product] =&gt; 12K816
          [Invoice Date] =&gt; 24/04/2018
          [Carriage] =&gt; 0.00
          [Carriage Tax Code] =&gt; T1
          [Order Number] =&gt; 224
      )
  )
  </code></pre>
  
  <p>Array 0 is for Sale 223 and Array 1 &amp; 2 are for Sale 224.</p>
  
  <p>The foreach that loops through this array and outputs to Excel is as follows:</p>
  
  <pre><code>foreach($export_array as $row) {
      if(!$flag) {
        // display field/column names as first row
        echo implode("\t", array_keys($row)) . "\n";
        $flag = true;
      }       
      array_walk($row, __NAMESPACE__ . '\cleanData');
      echo implode("\t", array_values($row)) . "\n";
    }
  </code></pre>
  
  <p>I only want to output the Carriage &amp; Carriage Tax Code values on the first iteration for each Sales Order Number but I don't know how to do this. I tried re writing the entire thing which grouped the data into a multidimensional array that was grouped by Order Number, which worked but then I failed in getting the export to work.</p>
  
  <p>Any pointers would be greatly appreciated</p>