After set array into foreach cant count that?

Viewed 47

i should find today timestamp and if count more than 3 return false if not return true

query :

while( $record = $result->fetchAssoc() ) { 
    $items[] = $record;
}

output :

Array
(
    [0] => Array
        (
            [timestamp] => 1570877769
        )

    [1] => Array
        (
            [timestamp] => 1570877783
        )

    [2] => Array
        (
            [timestamp] => 1510877794
        )

)

Foreach :

    foreach ($items as $Newarrays) {

    }

after use a foreach loop look :

Array
(
    [timestamp] => 1570877769
)
Array
(
    [timestamp] => 1570877783
)
Array
(
    [timestamp] => 1570877794
)

this step i want count timestamps to find 3 timestamp today but count return 1 and not work !

UPDATE FULL CODE:

$query->condition('node_revision.nid', $node->nid);

how do that? thanks for you helps...

1 Answers

Try like this. in this output I'm getting a count as 2

   $items = array(array('timestamp'=>1570877769),array('timestamp'=>1570877783),array('timestamp'=>1510877794));


    $currentdate=date("d-m-Y");

    $count = 0;
    foreach ($items as $newarrays) {
        if($currentdate == date("d-m-Y",$newarrays['timestamp'])){
            $count++;
        }
    }
    echo $count;
    exit;

https://paiza.io/projects/WpyO1P-9Oaj3G_gYq4VeQA

Related