I am trying to get the array elements within a range but failed to do so. Explaining it below.
$date_array = array('2012-08-02','2012-08-09','2012-08-16','2012-08-23');
$start_date = '2012-08-01';
$end_date = '2012-08-10';
I want to get the array elements from the $date_array within $start_date and $end_date.
i.e, output will be : 2012-08-02 and 2012-08-09.
Edit:
The array can be the following as well.
$date_array = array('2012-08-02','2012-08-10','2012-08-16','2012-08-23');
You can do that using
array_filterDocs and a callback that fulfills your needs:Take care of the order of the parameters and as well that you have these exact formats because only those can the done with a simple string comparison.
For PHP 5.2 compatibility and also to solve this for iterators and not only arrays, here is a more general approach: