Reputation: 69
I'm trying to plot an array, but if one date is NULL, the value go to 1/1/1970.
I have the code:
$date1 = $row['date_initial'];
$date2 = $row['date_end'];
$value = $row['value'];
$data1 = array(strtotime($date1)*1000,$value);
$data2 = array(strtotime($date2)*1000,$value);
$data8[] = array($data1,$data2);
echo json_encode($data8);
I get this array:
[[[1456531200000,"-12"],[1456704000000,"-12"]],[[1456531200000,"-16"],[0,"-16"]],[[1456617600000,"-13"],[1456790400000,"-13"]],[[1456704000000,"-14"],[0,"-14"]]]
It would be possible to change the null value date and to put the current date until the date is not empty? or remove this pair of array?
I proved:
$data8 = array_map('array_filter', $data8);
$data8 = array_filter($data8);
but it doesn't work in this case...
Upvotes: 0
Views: 44
Reputation: 350300
You could replace 0
timestamps with today's (mid-night) timestamp as follows:
$today = strtotime(date('Y-m-d')) * 1000; // convert to milliseconds
foreach($data8 as &$period) {
if(!$period[0][0]) $period[0][0] = $today;
if(!$period[1][0]) $period[1][0] = $today;
}
Upvotes: 0
Reputation: 26153
Test it while init
if( ! ($data1 = strtotime($date1))) $data1 = time();
$data1 = array($date1*1000,$value);
Upvotes: 3