将数组中的时间戳用于动态行为

问题描述 投票:0回答:1

我希望今天的timestamp等于3或小于3,如果不返回FALSE,则返回TRUE

我将时间戳转换为日期格式并过滤当前日期时间戳

我的数组:

Array
(
    [timestamp] => 1570819492
)
Array
(
    [timestamp] => 1570819505
)
Array
(
    [timestamp] => 1570819516
)
Array
(
    [timestamp] => 1570819525
)
Array
(
    [timestamp] => 1570819536
)
Array
(
    [timestamp] => 1532963273
)

代码在这里,但是没有用:

foreach ($items as $Newarrays) {

$timestamp=$Newarrays[timestamp];
$accessdate=format_date($timestamp, 'custom', 'd-m-Y' );
$currentdate=date("d-m-Y");

if ($accessdate === $currentdate) {
  if (count($timestamp) > 3) {

    return FALSE;

  } else {

    return TRUE;
  }
}
php arrays
1个回答
0
投票

我认为您必须尝试一下:

 // let's suppose you array seems to be like the array bellow : 
$items = [

    ["timestamp"=>"1570819492"],
    ["timestamp"=>"1570819505"],
    ["timestamp"=>"1570819516"],
    ["timestamp"=>"1570819525"],
    ["timestamp"=>"1570819536"]
    ];   

foreach ($items as $Newarrays) {

$timestamp=$Newarrays["timestamp"];
$accessdate=date('d-m-Y',$timestamp );
$currentdate=date("d-m-Y");

if ($accessdate === $currentdate) {
  if (count($timestamp) > 3) {

    return false;

  } else {

    return true;
  }
}

}
© www.soinside.com 2019 - 2024. All rights reserved.