tags:

views:

22

answers:

1

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
+3  A: 
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)));
Wrikken
no i need each weeks count so i need the week from 07-03-10 to 07-10-10 and the previous weeks count also
Matt
Wrikken
Also: you example is not a 2-week range b.t.w. Or am I understanding the 'range' you talk about incorrectly?
Wrikken
my range is from 7-10-10 to 6-27-10so it is 2 weeks and the previous example didnt work...still testing
Matt
@Wrikken,you need to reformat OP's time to make your solution work.
SpawnCxy
D'oh! strtotime makes one lazy....
Wrikken
Fixedededededed.
Wrikken