我正在创建一个论坛,并希望计算每天新帖子的出现频率。因此,每个帖子都有时间戳:
$post_1 = 1526083200;
$post_2 = 1524083200;
$post_3 = 1523083200;
$post_4 = 1522083200;
我该怎么做才能确定每天提交帖子的频率。最终输出示例:
echo 'Every '. $frequency .' day(s)';
答案 0 :(得分:3)
您也许可以尝试这样的事情:
$post_1 = 1526083200;
$post_2 = 1524083200;
$post_3 = 1523083200;
$post_4 = 1522083200;
// I add all the value in an array then sort the array to get the min and max value
$date_array = [$post_1, $post_2, $post_3, $post_4];
sort($date_array);
// Now I can select the min date and the max date
$min_date = $date_array[0];
$max_date = $date_array[count($date_array) - 1];
// I calculate the diff to get the number of day during this period
$datediff = $max_date - $min_date;
// I divide this value with the number or article post during this period
$frequency = $datediff / count($date_array);
// Now I transform this value in number of day
$frequency = round($frequency / (60 * 60 * 24));
在您的示例中,这就是您得到的:
4
2018-03-26
2018-05-12
46
12
听起来很有价值,每12天发表一篇文章。
是您要找的东西吗?
答案 1 :(得分:1)
假设您想要一般频率:
在您的示例中:
$post_1 = 1526083200;
$post_2 = 1524083200;
$post_3 = 1523083200;
$post_4 = 1522083200;