0

我正在开发一个统计应用程序,我想输出一天中发生的交互量。

我有一个多维数组,可以从数据库中提取所有信息,这是一个示例:

 [0] => Array
            (
                [date] => 2012-07-26
                [location] => 709c6d241674ca22
                [action] => start_scan
            )

        [1] => Array
            (
                [date] => 2012-07-26
                [location] => 709c6d241674ca22
                [action] => scan_displayed
            )

        [2] => Array
            (
                [date] => 2012-07-27
                [location] => 709c6d241674ca22
                [action] => lower_device
            )

        [3] => Array
            (
                [date] => 2012-07-27
                [location] => 709c6d241674ca22
                [action] => how_to_use_displayed
            )

        [4] => Array
            (
                [date] => 2012-07-27
                [location] => 709c6d241674ca22
                [action] => raise_device
            )

        [5] => Array
            (
                [date] => 2012-07-28
                [location] => 709c6d241674ca22
                [action] => scan_displayed
            )

我可以通过格式化日期来计算每次交互发生的日期:

date('D', strtotime('2012-07-26'));

我的问题是如何计算一周中的每一天发生了多少交互然后输出它,例如:

[Sunday] => 2
[Monday] => 3
[Tueday] => 1
[Wednesday] => 5
[Thursday] => 10
[Friday] => 4
[Saturday] => 9

任何建议都非常感谢!

4

1 回答 1

1
$dates = array();
foreach($data as $item) {
    $day = date('l', $item['date']);
    $dates[$day]++;
}
var_dump($dates);

您可能希望将数组声明为 $dates = array('Monday'=>0, 'Tuesday'=>0 .... ) 以获取包含没有交互的日期的数组。

于 2012-08-12T21:40:42.257 回答