php - How can I create a foreach loop that will increase a variable for ranges between 2 dates? -
i have following array:
array ( [0] => array ( [dob] => 1990-01-01 ) [1] => array ( [dob] => 1979-10-01 ) [2] => array ( [dob] => 1982-05-07 ) [3] => array ( [dob] => 1967-08-01 ) [4] => array ( [dob] => 1967-10-01 ) [5] => array ( [dob] => 1965-03-01 ) [6] => array ( [dob] => 1970-03-03 ) [7] => array ( [dob] => 1977-01-03 ) [8] => array ( [dob] => 1993-10-06 ) [9] => array ( [dob] => 1991-09-10 ) [10] => array ( [dob] => 1994-02-02 ) [11] => array ( [dob] => 1994-08-03 ) [12] => array ( [dob] => 1994-08-03 ) [13] => array ( [dob] => 1997-04-03 ) [14] => array ( [dob] => 1997-04-03 ) [15] => array ( [dob] => 1997-04-03 ) [16] => array ( [dob] => 1997-04-03 ) [17] => array ( [dob] => 1947-02-16 ) [18] => array ( [dob] => 1957-10-17 ) [19] => array ( [dob] => 1980-01-03 ) [20] => array ( [dob] => 1985-04-04 ) [21] => array ( [dob] => 1998-02-03 ) [22] => array ( [dob] => 1969-06-06 ) [23] => array ( [dob] => 2000-03-03 ) [24] => array ( [dob] => 1980-04-02 ) [25] => array ( [dob] => 1973-03-03 ) [26] => array ( [dob] => 1984-06-14 ) [27] => array ( [dob] => 1976-10-17 ) [28] => array ( [dob] => 2003-03-01 ) [29] => array ( [dob] => 1972-05-05 ) )
i want count dates between selected years, example between 1970/01/01 , 1980/01/01 should 1. have tried following each:
foreach($data $item){ if ($item['dob'] == ('>=' . '1970-01-01' && '<' . '1980-01-01')) { $a++; }
i pass variables array convert json array populate chart, im getting following output:
{"1970s":30,"1980s":0,"1990s":0}
what syntax please? thanks
it pass dates strtotime,
<?php $startdate = '1970-01-01'; $enddate = '1980-01-01'; foreach($data $item){ if ((strtotime($item['dob'])>=strtotime($startdate)) && (strtotime($item['dob'])<strtotime($enddate))) { $a++; } ?>
Comments
Post a Comment