text: Q:
  
  Loop through arrays and compare timestamps
  
  I have two arrays that I like to loop through and compare the dates between each array.
  $newArray = Array (
      [0] => Array (
              [id] => 1
              [date] => 26-11-2013 9:30:56 PM
          )
      [1] => Array (
              [id] => 2
              [date] => 30-11-2013 11:20:12 AM
          )
      [2] => Array (
              [id] => 3
              [date] => 26-11-2013 9:30:56 PM
          )
      [3] => Array (
              [id] => 4
              [date] => 30-11-2013 11:20:12 AM
          )
  }
  
  $oldArray = Array (
      [0] => Array (
              [id] => 1
              [date] => 26-11-2013 9:30:56 PM
          )
      [1] => Array (
              [id] => 2
              [date] => 26-11-2013 9:30:56 PM
          )
      [2] => Array (
              [id] => 3
              [date] => 26-11-2013 9:30:56 PM
          )
  }
  
  foreach ($newArray as $newPhoto) {
      foreach ($oldArray as $oldPhoto) {
          if (strtotime($newPhoto['date']) != strtotime($oldPhoto['date'])) {
              // download new photo
          }
      }
  }
  
  I realize that placing the foreach with a foreach is not going to cut it. What is the best way to loop through each of these arrays and compare the dates?
  The $newArray has the latest photos and compares with the $oldArray if the timestamps do not match or there is a new one in the list, download the new images.
  In the example, I would be downloading the second and fourth images and ignoring the others.
  
  A:
  
  I'd do it like this. It does not make any assumptions about the indices of either array, and will be still be fairly efficient as $oldArray grows in size.
  // index $oldArray by id for speed
  $index = array();
  foreach ($oldArray as $photo) {
      $index[$photo['id']] = $photo['date'];
  }
  
  // iterate through new photos, checking if each one needs downloading
  foreach ($newArray as $photo) {
      if (!isset($index[$photo['id']]) // photo is not in $oldArray
              || strtotime($photo['date']) > strtotime($index[$photo['id']])) { // photo is in $oldArray, but a new version is available
          // download new photo
      }
  }
  
  