What is causing the second function to miss the last item of the second array?
$x = array(
'Mon Sep 12 12:19:33 +0000 2011',
'Tue Sep 13 14:19:33 +0000 2011',
'Wed Sep 14 01:19:33 +0000 2011',
'Thu Sep 15 07:19:33 +0000 2011',
'Fri Sep 16 16:19:33 +0000 2011',
'Fri Sep 16 19:19:33 +0000 2011',
'Sat Sep 17 15:57:37 +0000 2011',
'Sun Sep 18 13:01:39 +0000 2011',
'id' => array('a','b')
);
//Create function to turn timestamps into unix timestamps so
function textTimeToUnixTime($x) {
$z = array();
for($i = 0; $i < count($x) - 1; $i++) {
array_push($z, strtotime($x[$i]));
}
return $z;
}
function timeDifference($x) {
//Get Time Difference of the timestamps
array_reverse($x);
$z = array();
for($i = 0; $i < count($x) - 1; $i++) {
$a = $x[$i+1] - $x[$i];
array_push($z, $a);
}
return $z;
}
Output
array(8) {
[0]=> int(1315829973)
[1]=> int(1315923573)
[2]=> int(1315963173)
[3]=> int(1316071173)
[4]=> int(1316189973)
[5]=> int(1316200773)
[6]=> int(1316275057)
[7]=> int(1316350899)
}
array(7) {
[0]=> int(93600)
[1]=> int(39600)
[2]=> int(108000)
[3]=> int(118800)
[4]=> int(10800)
[5]=> int(74284)
[6]=> int(75842)
}
Because in timeDifference the last loop it calls $x[7+1] but there’s no such $x[8] but rather a $x[‘id’] so it only works until 7.
Anyway, if you’re comparing one time with the next one, the ammount of differences should be 1 less than the ammount of times.