如果它们之间的时间少于 20 分钟,我如何从数组中打印出我的值?
This is my foreach for myArray:
foreach ($cooltransactions as $key=>$value)
{
$array[$key] = array('cardid' => $cooltransactions[$key]['cardid'],'created' => strtotime($cooltransactions[$key]['created']));
}
$newArray=array();
$i=0;
foreach($array as $k=>$v){
$id=$array[$k]['cardid'];
$time=$array[$k]['created'];
foreach($array as $k1=>$v1){
if($k<$k1){
if($array[$k1]['cardid']==$id){
if(compare($time,$array[$k1]['created'])){
$newArray[$i]['cardid']=$id;
$newArray[$i]['created']=date('d-m-y H:i:s', $time['created']);
$i++;
}
}
}
}
}
function compare($firsttime, $secondtime){
$interval = $firsttime-$secondtime;
$dif=round(abs($interval) / 60);
if ($dif < 2 || $dif < -2 ) {
return true;
}
}
print_r($newArray);
这就是我得到的:
Array (
[0] => Array ( [cardid] => 56324 [created] => 01-01-70 01:00:00)
[1] => Array ( [cardid] => 56324 [created] => 01-01-70 01:00:00)
[2] => Array ( [cardid] => 21352 [created] => 01-01-70 01:00:00)
[3] => Array ( [cardid] => 21352 [created] => 01-01-70 01:00:00)
)
但这是我想要的输出:
Array (
[1] => Array ( [Cardid] => 21352 [created] => 02-02-13 11:11:41 )
[2] => Array ( [Cardid] => 21352 [created] => 02-02-13 10:59:48 )
)