多维数组在两个日期的中间找到

I have an array like the one below

array(
    "hgfh"  => array("s" => "2011-11-28T07:00-04:00", "e" => "2011-11-29T06:59-04:00"),
    "hgfh"    => array("s" => "2011-11-29T07:00-04:00", "e" => "2011-11-30T06:59-04:00"),
    "hgfh"    => array("s" => "2011-11-30T07:00-04:00", "e" => "2011-12-01T06:59-04:00"),
    "hgfh"    => array("s" => "2011-12-01T07:00-04:00", "e" => "2011-12-02T06:59-04:00"),
    "hgf"     => array("s" => "2011-12-02T07:00-04:00", "e" => "2011-12-05T06:59-04:00"),
    "sog"     => array("s" => "2011-12-05T07:00-04:00", "e" => "2011-12-06T06:59-04:00"),
    "gfd"     => array("s" => "2011-12-06T07:00-04:00", "e" => "2011-12-07T06:59-04:00"),
    "gfd"     => array("s" => "2011-12-07T07:00-04:00", "e" => "2011-12-08T06:59-04:00"),
    "bob"  => array("s" => "2011-12-08T07:00-04:00", "e" => "2011-12-09T06:59-04:00"),
    "tree" => array("s" => "2011-12-09T07:00-04:00", "e" => "2011-12-11T23:00-04:00"),
);

For example and I need to determine if the current date("c"); is between the "s" and "e" in that array and then get the key. So it would say today is the 2011-11-30T09:50-04:00 and determine that the key is hgfh Is there any quick and dirty method to do so? I'm a bit worried about performance, so if there is a method that may be better performance wise, I would appreciate that.

Storing dates as strings, especially when you want to do such 'between' comparisons, will be painful no matter what you do. You should be storing the raw PHP timestamp values that represent those times, e.g.

array(
   'hgfh' => array('s' => 1000, 'e' => 2000)
   etc...
)

(using obviously fake timestamp values). Then it becomes a simple matter of:

$check = strtotime('2011-11-30T09:50-04:00');
foreach($yourarray as $key => $times) {
   if (($check >= $times[s]) && ($check <= $times[e]))
       break;
   }
}
echo $key;

Otherwise you're stuck converting those strings to time values every time you run the check loop, which gets expensive very fast. Always store times/dates in native formats, and convert to human-readable only as necessary.

    function get_matches($date_array) {

        $new_date_array = array_filter($date_array, 'match_dates');

        print_r(array_keys($new_date_array));

    }

    function match_dates($array_element) {

       return date('c') >= $array_element['s'] && date('c') <= $array_element['e'] ? true : false;

    }

"So it would say today is the 2011-11-30T09:50-04:00"

This line from the question suggests that there is an attempt to use calendar dates and localized time stamps interchangeably.

This is better than attempting to switch in between calendar dates and pure time stamps, but it is still ambiguous.

In case it is about calendar dates, store them as such, e.g. 2011-11-24

And in case performance matters, you can store those calendar dates as e.g. modified Julian date.

Time stamps represent an absolute point of time, usually in seconds.

Localized time stamps represent the combination of an absolute point of time, usually in seconds, plus an effective time zone offset, usually in hours or minutes.

Calendar dates represent, well, a calendar date - which begins and ends at time stamps that depend on what the jurisdiction of a certain place defines.

Independent of whether you go for ISO-8601 string representations or numerical representations, always take care to be clear about your intentions.

Time seems easy at first glance.

But time instead is actually just one of the easiest things to get wrong.