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.