Hi,
In the code below when status changes from 0 to 1 the difference is calculated.
When status is 0 the difference of timestamp is not calculated.
Please tell me how to do it.
i.e,
In one row I want the difference like $tdiff = 2008-06-13 00:30:00-2008-06-13 00:10:00
<?php
$values=array(
"0#2008-06-13 00:10:00#master",
"0#2008-06-13 00:20:00#master",
"0#2008-06-13 00:30:00#master",
"1#2008-06-13 00:40:00#stud",
"0#2008-06-13 00:50:00#stud",
"1#2008-06-13 01:10:00#stud"
);
$i=0;
$outset = array();
$status = array();
$aset = 0;
foreach($values as $v) //For each element in the values array
{
// Split the value by hash
$vals = explode('#', $v);
// If this is the first loop, set the previous status
if($i == 0) {$previous_value = $vals[0]; $i=1; $starttime = $vals[1];}
// If the previous =0 and the current is 1, store the values in a new array for output
if($previous_value == 0 && $vals[0] == 1)
{
$aset = 1;
$tdiff = date('h:i:s', strtotime($vals[1]) - strtotime($starttime));
$outset[] = $starttime.' '.$vals[1].' '.$tdiff.' '.$vals[2];