Hi,
There is a piece of code where $time[$j] should be 2008-06-13 00:10:00 and 0#2008-06-13 00:50:00
$time[$i] should be 2008-06-13 00:40:00 and 2008-06-13 01:10:00
ie. when the status changes from 0 to 1, the timestamp should be assigned as when status was 0 initially.
In the above code status was 0 at 2008-06-13 00:10:00.
again it was 0 at 2008-06-13 00:50:00
<?php
$stack = array();
$val = array();
$time = array();
$values=array("0#2008-06-13 00:10:00","0#2008-06-13 00:20:00","0#2008-06-13 00:30:00","1#2008-06-13 00:40:00","0#2008-06-13 00:50:00","1#2008-06-13 01:10:00");
foreach($values as $v){
$val1=split("#",$v);
array_push($val,$val1[0]);
array_push($time,$val1[1]);
}
//$val = array(0,0,1,0,1,0,0,1,0,0,1,0);
//$val = array(0,0,0,0,0,1,1,1,1,0,1,1);
$previous_value = $val[0];
$i = 0;
foreach ($val as $value){
$this_value = $value;
if($previous_value ==0 && $this_value ==1)
array_push($stack, "$time[$j]#$time[$i]");
$previous_value = $this_value;
$i++;
$j=$i-1;
}
echo"<pre>";
print_r($val);
print_r($stack);
echo"</pre>";
Please tell me how to assign the timestamp from when it was 0.