それらの間に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 )
)