我的 JSON 看起来像这样:
[{"NAME":"Burger Man","USER_ID":"14","TIMESTAMP":"1367668271","ACTION":"enabled"},
{"NAME":"Test McTest","USER_ID":"16","TIMESTAMP":"1368092635","ACTION":"disabled"},
{"NAME":"Test McTest","USER_ID":"16","TIMESTAMP":"1368132268","ACTION":"enabled"}]
从这些数据中,我想计算一个人在当前日期之前活跃的天数。如果一个人在此数据中仅被发现一次,则意味着他一直处于活动状态,对于多次被发现的人,我必须以某种方式计算他们的活动时间。
$data = json_decode(file_get_contents($url));
$workers2 = array();
foreach($data as $mydata){
$workers2[] = array($mydata->NAME, $mydata->ACTION, date('Y-m-d h:i:s',$mydata->TIMESTAMP));
}
echo '<pre>';
print_r($workers2);
echo '</pre>';
输出以下内容:
Array
(
[0] => Array
(
[0] => Burger Man
[1] => enabled
[2] => 2013-05-04 02:51:11
)
[18] => Array
(
[0] => Test McTest
[1] => disabled
[2] => 2013-05-09 12:43:55
)
[19] => Array
(
[0] => Test McTest
[1] => enabled
[2] => 2013-05-09 11:44:28
)
)
我想我必须将所有名称插入一个数组并检查重复项。如果某个名字没有重复,我知道他一直都很活跃。也可以随时激活和禁用一个人。如何从这些数据中获取每个人的综合活动时间?