0

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I edited it slightly for my purposes but it seems to work perfectly!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.