Okay..first of all, I appreciate everyone's help. Nickb, thanks for the help and the demos. As I surmised earlier, your suggestion that I might be trying to access an element that doesn't exist in the array was absolutely the case. What I am trying to do here is a pretty important part of a site I am creating..this whole mess will serve as a function in a class that checks reservation dates.
This is my first shot at Stack Overflow, so forgive me but I probably should have put more information in my initial question, but I was convinced I knew why the code wasn't working..which was completely incorrect!
See, since I always needed to know the current element, plus the next element in the array, my code was always breaking on the very last run of the loop, because it was trying to access the current key, plus the next one (which didn't exist on the last try).
Now, the real frustrating part is I screwed around with the for loop for this code all night and I still could not get it to cleanly go through every item without breaking...I would always over-run on that last item of the array and pull the error. I think the problem all along was that I never needed to go through every item in the array, just up to the second to last item (plus check the next one) then quit the loop.
Here is my code that finally works, but I don't really like it...I have a feeling there are some simple fixes in syntax and other areas that will make this more efficient...if not, the so be it...this is by the way, basically my testing code full of echos to see what was actually happening, but it is finally doing everything right:
$count = (count($session_dates)-1); //never could get that last item to not trigger error, so subtracting one from the count was the only thing to end my frustration!!!but as I write this answer I think I see why and that is because we don't need to go through each item of the array, just each but the last item echo '<p>'.$count.' this is the count of session dates </p>'; for ($i=0; $i<$count; $i++){ $unix_one = $session_dates[$i+1]->format('U'); //make some variables that are in the date format I want to visualize for echoing $unix_echo_one = $session_dates[$i+1]->format("n".'/'."j".'/'."Y"); $unix_two = $session_dates[$i]->format('U'); $unix_echo_two = $session_dates[$i]->format("n".'/'."j".'/'."Y"); //see if the difference is greater than one day if(($unix_one-$unix_two)/86400>1){ echo 'these dates are absolutely not consecutive, you fail!!'; //we only need one occurrence to wreck what we are trying to do, so just exit if it happens. exit(); } //I needed to see if any of the loop was happening to help try and figure this out!! echo '<p>'.$unix_echo_one.'||'.$i.'||'.$unix_echo_two.'</p>'; }