0
votes

I have a Multi-Dimensional Array and need to extract the data from it based on if the datetime field is between a certain date range.

The datetime column is in unix timestamp.

I already know how to sort the array based on the date, but now I want to only return portions of the array if the datetime field is from a certain month or certain year.

The keys need to be preserved.

Array example:

<?
$videoids = array(

    'iD-7H6Rv-SM' => array
    (
    'datetime' => '1421693217',
    'title' => 'title',
    'description' => 'description',
    'channel' => 'info',
    'url' => 'url'
    ),

    'X9tzt0MEIRI' => array
    (
    'datetime' => '1422784090',
    'title' => 'title',
    'description' => 'description',
    'channel' => 'info',
    'url' => 'url'
    ),

    'TaFgrY9HsUA' => array
    (
    'datetime' => '1418712579',
    'title' => 'title',
    'description' => 'description',
    'channel' => 'info',
    'url' => 'url'
    ),

    'i9PGMYb7Aoc' => array
    (
    'datetime' => '1404178390',
    'title' => 'title',
    'description' => 'description',
    'channel' => 'info',
    'url' => 'url'
    ),

);?>

The first 2 inner arrays datetime fields are from year 2015

The last 2 inner arrays datetime fields are from year 2014

how can I extract only the inner arrays containing a time stamp with year 2014?

I want to display data from the array from year and possibly even break it down by month.

Example:

click here to display data from 2015

click here to display data from January

1

1 Answers

1
votes

fore year:

$search_year = 2015; // $_REQUEST['year']
foreach ($videoids AS $video) {
    if(@date('Y', $video['datetime']) == $search_year) {
        echo '<pre>' . print_r($video, true) .  '</pre>';
    }
}

http://php.net/manual/en/function.date.php