Jump to content

timestamp


rashmi_k28

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/110191-timestamp/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.