Lets say all I have is a bunch of timestamps that represent the time of the click like this:
1298888707, 1298891521, 1298907490, 1298999649, 1299002856, 1299003880, 1299055121, 1299059489, 1299059576, 1299062919, 1299068122, 1299079105, 1299080116, 1299081230, 1299086709, 1299144900, 1299149635, 1299167764, 1299169121, 1299169661, 1299172766, 1299173590, 1299196306, 1299210407, 1299226740, 1299227733, 1299228702, 1299229643, 1299230315, 1299231007, 1299232040, 1299239872, 1299243267, 1299243584, 1299244186, 1299244830, 1299246051, 1299246365, 1299246526, 1299247302, 1299247540, 1299247637
What is the easiest and fastest way to convert those in a "click by day" stats array? End result would be a php ar开发者_StackOverflowray with something like this:
$clicks = array(4, 25, 0, 34, 23);
Where 4 would be the number of clicks on day 0, 25 the number of clicks on day 1, 0 the number of clicks on day 2, etc...
Any ideas? Many thanks!
If it's OK to have the array keyed by dates, then you could do something like this:
<?php
$hits = array();
foreach ($array_of_timestamps as $timestamp)
{
$currentDate = date('Y-m-d', $timestamp);
if (!isset($hits[$currentDate]))
{
$hits[$currentDate] = 0;
}
$hits[$currentDate]++;
}
精彩评论