Matt Elhotiby
Matt Elhotiby

Reputation: 44066

PHP Looping based on date

ok so i have this array of about 151 elements and there is a date field as one of the elements. The array is a two week range. I want to count how many elements are in the first week and how any are in the second week. Here is my example array.

[0] => Array
    (
        [0] => 4d50
        [date] => 07-10-2010
        [telephone] => something
        [Sno] => 1
     )

[1] => Array
    (
        [0] => 4g50
        [date] => 07-03-2010
        [telephone] => something
        [Sno] => 1
    )

[2] => Array
    (
        [0] => 4s50
        [date] => 06-29-2010
        [telephone] => something
        [Sno] => 1

Upvotes: 0

Views: 51

Answers (1)

Wrikken
Wrikken

Reputation: 70460

function getweek($a){
   //altered code., m-d-Y is no a format strtotime likes):
   return  DateTime::createFromFormat('m-d-Y',$a['date'])->format('W');
}
var_dump(array_count_values(array_map('getweek',$inputarray)));

Upvotes: 3

Related Questions