title: Comparing previous and current values from an array
body: <p>I am trying to create a new CSV file from an existing CSV file with additional data. I used fgetcsv to access the data from the existing CSV file and put it inside an array. After putting the csv file contents to an array, the array turned out as a 2-D array with data that looks like this:</p>
  
  <pre><code>Array {
       [0] =&gt;
          Array {
              [0] =&gt; "Data1", "Data2", Data3
          }
  }
  </code></pre>
  
  <p>So what I did was create a new array from this by imploding first the array values then exploding like so:</p>
  
  <pre><code>for($i = 0; $i &lt; $myArray; $i++) {
      $tempString = implode(" ", $myArray);
      $tempArray = explode (" ", $tempString);
  }
  </code></pre>
  
  <p>With this my array now looks like so:</p>
  
  <pre><code>Array {
        [0] =&gt; "Data1"
        [1] =&gt; "Data2"
        [3] =&gt; "Data3" //endDate
  }
  
  Array {
        [0] =&gt; "Data1"
        [1] =&gt; "Data2"
        [3] =&gt; "Data3" //endDate
  }
  </code></pre>
  
  <p>Now, I would like to add a fourth value on the array for startDate. I want the startDate to be equal to the endDate + 1. So for example the endDate is 20th November, then the endDate for the next Array is 21st November. The thing is I'm not entirely sure how to implement that. I've tried adding this inside the for loop just like pretty much all the examples and articles I've read:</p>
  
  <pre><code>$d3 = $tempArray[3]; //Data3
  if($d3 == $previous) {
        //do some things here
  }
  $previous = $d3 + 1;
  </code></pre>
  
  <p>The thing with this is the dates tend to be in groups. For example arrays 1-8 is 20th November then array 9-20 is 30th November. Because of this, only the first date among these "groups" get the previous value so only array 9 would get 21st November. How can I tell my code that while the end date is the same, it does not change the start date? Then if it does, it should get the previous date and add 1 day to it? Please help.</p>
  
  <p>Also, I know there might be something wrong with how I'm handling the arrays so if anybody knows how to handle this better, faster and more efficiently, I would appreciate it.</p>