获取满足特定条件的数组项计数ini php

时间:2018-11-27 05:52:49

标签: php arrays count

如何计算条件中的数组:

$array = array(
    '2018/11/24',
    '2018/11/25',
    '2018/12/1',
    '2018/12/2',
    '2018/12/3'
); //specified date

$start = strtotime('2018/11/23');

$then = strtotime('2018/11/26');

如何计算符合

的数组
criteria >= $start and <=$then

1 个答案:

答案 0 :(得分:0)

将foreach循环用作第一次尝试:

$array = array(
    '2018/11/24',
    '2018/11/25',
    '2018/12/1',
    '2018/12/2',
    '2018/12/3'
);

$start = strtotime('2018/11/23');
$then = strtotime('2018/11/26');

foreach ($array as $date)
    strtotime($date) >= $start && strtotime($date) <= $then and $count++;

echo "$count elements matches criteria";