标签云

微信群

扫码加入我们

WeChat QR Code

I have created an array with 10 timestamps each 1 day apart:$data_points = array();$now = time();$one_day = 60 * 60 * 24;for($i = 1; $i <= 10; ++$i) {$key = $now - ($one_day * $i);$data_points[$key] = 0;}print_r($data_points);Array([1328642414] => 0[1328556014] => 0[1328469614] => 0[1328383214] => 0[1328296814] => 0[1328210414] => 0[1328124014] => 0[1328037614] => 0[1327951214] => 0[1327864814] => 0)Now I have a array of tasks that have started at various times in the last 10 days, I want to see which day my task fell into. I was going to loop through each $data_point and see if the start time is greater than the current day and less than the next, then increment that data pointis there a better way to do this?Thanks


Instead of using timestamps in your array you could use "yyyy-mm-dd" and then use DateTimes instead of timestamps and increment respective days using DateTime->format().

2019年04月19日30分38秒

What does your tasks array look like?

2019年04月19日30分38秒

If you don't have DateTime, you can use date to get a "Y-m-d" formatted representation of a timestamp. php.net/manual/en/function.date.php

2019年04月19日30分38秒

I should have been more clear, the data_points are 1 day apart but they wont wont be from 00:00 to 23:59 they could be from 08:56 to 08:55

2019年04月18日30分38秒

Unfortunately the DateTime Class ins't available in my environment

2019年04月19日30分38秒