How to convert last desired days to weeks in PHP - php

Hi i have a function who returns me the last 30 days from current day excluding current date. Function is below
function getLastNDays($days, $format = 'd-m-Y'){
$m = date("m"); $de = date("d")-1; $y= date("Y");
$dateArray = array();
for($i=0; $i<=$days-1; $i++){
$dateArray[] = date($format, mktime(0,0,0,$m,($de-$i),$y));
}
$dateArray[] = 'x';
return array_reverse($dateArray);
}
so i am using this function
$sevenarr = getLastNDays(30);
and it is returning me this result
Array
(
[0] => x
[1] => 19-06-2018
[2] => 20-06-2018
[3] => 21-06-2018
[4] => 22-06-2018
[5] => 23-06-2018
[6] => 24-06-2018
[7] => 25-06-2018
[8] => 26-06-2018
[9] => 27-06-2018
[10] => 28-06-2018
[11] => 29-06-2018
[12] => 30-06-2018
[13] => 01-07-2018
[14] => 02-07-2018
[15] => 03-07-2018
[16] => 04-07-2018
[17] => 05-07-2018
[18] => 06-07-2018
[19] => 07-07-2018
[20] => 08-07-2018
[21] => 09-07-2018
[22] => 10-07-2018
[23] => 11-07-2018
[24] => 12-07-2018
[25] => 13-07-2018
[26] => 14-07-2018
[27] => 15-07-2018
[28] => 16-07-2018
[29] => 17-07-2018
[30] => 18-07-2018
)
So what i want now is to show the result days as weeks. so till now i am not able to figure it out how to do this with the upper function. please help me with some logic how can i update my function so i get the weeks of last desired days. For example there is last 30 days it will convert days into weeks
Output i want is
Array
(
[0] => Array
(
['start-date'] => 18-07-2018
['end-date'] => 12-07-2018
)
[1] => Array
(
['start-date'] => 11-07-2018
['end-date'] => 5-07-2018
)
[2] => Array
(
['start-date'] => 04-07-2018
['end-date'] => 28-06-2018
)
[3] => Array
(
['start-date'] => 27-06-2018
['end-date'] => 21-06-2018
)
[4] => Array
(
['start-date'] => 20-06-2018
['end-date'] => 19-06-2018
)
desired output
[weekArray] => Array
(
[1] => Array
(
[0] => 2018-06-19
[1] => 2018-06-20
[2] => 2018-06-21
[3] => 2018-06-22
[4] => 2018-06-23
[5] => 2018-06-24
[6] => 2018-06-25
)
[2] => Array
(
[0] => 2018-06-26
[1] => 2018-06-27
[2] => 2018-06-28
[3] => 2018-06-29
[4] => 2018-06-30
[5] => 2018-07-01
[6] => 2018-07-02
)
[3] => Array
(
[0] => 2018-07-03
[1] => 2018-07-04
[2] => 2018-07-05
[3] => 2018-07-06
[4] => 2018-07-07
[5] => 2018-07-08
[6] => 2018-07-09
)
[4] => Array
(
[0] => 2018-07-10
[1] => 2018-07-11
[2] => 2018-07-12
[3] => 2018-07-13
[4] => 2018-07-14
[5] => 2018-07-15
[6] => 2018-07-16
)
[5] => Array
(
[0] => 2018-07-17
[1] => 2018-07-18
[2] => 2018-07-19
)
)

Check below function to get the days range into weeks. I have considered Sunday as first day of week.
<?php
function getLastNDays($days, $format = 'Y-m-d'){
$retunData = array();
$m = date("m"); $de = date("d")-1; $y= date("Y");
$dateArray = array();
for($i=0; $i<=$days-1; $i++){
$dateArray[] = date($format, mktime(0,0,0,$m,($de-$i),$y));
}
//$dateArray[] = 'x';
$resultArray = array_reverse($dateArray);
// After get the date Range find out Statrt & End date
$start_date = $resultArray[0];
$end_date = $resultArray[count($resultArray)-1];
$from_date = new DateTime($start_date);
$to_date = new DateTime($end_date);
$interval = new DateInterval('P1D');
$dateRange = new DatePeriod($from_date, $interval, $to_date);
$week_number = 1;
$weekArray = array();
foreach ($dateRange as $key => $date) {
$weekArray[$week_number][] = $date->format('Y-m-d');
$mod = $key%7;
if($mod == 6){
$week_number++;
}
/*
if ($date->format('w') == 6) {
$week_number++;
}
*/
}
$retunData['weekArray'] = $weekArray;
//Get the Start & End Date each week.
$weekrange = array_map(function($w) {
return 'start: ' . array_shift($w)
. ', end: ' . array_pop($w); },
$weekArray);
$retunData['weekRange'] = $weekrange;
return $retunData;
}
$retunData = getLastNDays(30); // Call your custom function.
echo '<pre>';
print_r($retunData);
exit;
?>
Your Output will be as per the date range.
Array
(
[weekArray] => Array
(
[1] => Array
(
[0] => 2018-06-20
[1] => 2018-06-21
[2] => 2018-06-22
[3] => 2018-06-23
[4] => 2018-06-24
[5] => 2018-06-25
[6] => 2018-06-26
)
[2] => Array
(
[0] => 2018-06-27
[1] => 2018-06-28
[2] => 2018-06-29
[3] => 2018-06-30
[4] => 2018-07-01
[5] => 2018-07-02
[6] => 2018-07-03
)
[3] => Array
(
[0] => 2018-07-04
[1] => 2018-07-05
[2] => 2018-07-06
[3] => 2018-07-07
[4] => 2018-07-08
[5] => 2018-07-09
[6] => 2018-07-10
)
[4] => Array
(
[0] => 2018-07-11
[1] => 2018-07-12
[2] => 2018-07-13
[3] => 2018-07-14
[4] => 2018-07-15
[5] => 2018-07-16
[6] => 2018-07-17
)
[5] => Array
(
[0] => 2018-07-18
)
)
[weekRange] => Array
(
[1] => start: 2018-06-20, end: 2018-06-26
[2] => start: 2018-06-27, end: 2018-07-03
[3] => start: 2018-07-04, end: 2018-07-10
[4] => start: 2018-07-11, end: 2018-07-17
[5] => start: 2018-07-18, end:
)
)

Related

Grouping consecutive dates in an array together in PHP ignoring weekends and bank holidays

I have an array of dates
$dates = array("2019-04-09","2019-04-17","2019-04-18","2019-04-23","2019-04-24","2019-04-26","2019-04-29","2019-04-30");
what i would like is to pass the $date array through a function and that function would group consecutive working days together to produce the following format.
$newarray = array(
[0]=>array('start' => '2019-04-09','end' => '2019-04-09'),
[1]=>array('start' => '2019-04-17','end' => '2019-04-24'),
[2]=>array('start' => '2019-04-26','end' => '2019-04-30'),
);
Working days are non weekend and non uk bank holidays. I have bank holidays already in another array)
$bankholidays = array(
[0] => 2018-01-01
[1] => 2018-03-30
[2] => 2018-04-02
[3] => 2018-05-07
[4] => 2018-05-28
[5] => 2018-08-27
[6] => 2018-12-25
[7] => 2018-12-26
[8] => 2019-01-01
[9] => 2019-04-19
[10] => 2019-04-22
[11] => 2019-05-06
[12] => 2019-05-27
[13] => 2019-08-26
[14] => 2019-12-25
[15] => 2019-12-26
[16] => 2020-01-01
[17] => 2020-04-10
[18] => 2020-04-13
[19] => 2020-05-04
[20] => 2020-05-25
[21] => 2020-08-31
[22] => 2020-12-25
[23] => 2020-12-28
)
the following function gives me date ranges in the format i require but doesn't take into consideration weekends and bank holidays
function genarray($dates) {
$i=0;
$j=1;
$diff=86400;
$period = $diff;
$nrInterval=0;
$intervals[$nrInterval]['start'] = $dates[$i];
$intervals[$nrInterval]['end'] = $dates[$i];
while($j<count($dates)){
if(strtotime($dates[$j])-strtotime($dates[$i]) == $period){
$intervals[$nrInterval]['end'] = $dates[$j];
$j++;
$period+=$diff;
} else{
$i=$j;
$j++;
$nrInterval++;
$intervals[$nrInterval]['start'] = $dates[$i];
$intervals[$nrInterval]['end'] = $dates[$i];
$period = $diff;
}
}
return $intervals;
}
$dates = array("2019-04-09","2019-04-17","2019-04-18","2019-04-19","2019-04-23","2019-04-24","2019-04-26","2019-04-29","2019-04-30");
$tmp = genarray($dates);
print_r($tmp);
gives me
Array
(
[0] => Array
(
[start] => 2019-04-09
[end] => 2019-04-09
)
[1] => Array
(
[start] => 2019-04-17
[end] => 2019-04-19
)
[2] => Array
(
[start] => 2019-04-23
[end] => 2019-04-24
)
[3] => Array
(
[start] => 2019-04-26
[end] => 2019-04-26
)
[4] => Array
(
[start] => 2019-04-29
[end] => 2019-04-30
)
)
Can anyone help please? I just cant get my head around where to go from here.

Create 1 "outer" array from multiple loops that return an "inner" array

The requirement is to produce a list of dates for specific days within a defined period, i.e every Thursday for May 2019 through September 2019.
Expecting the format to be:
Array
(
[0] => 2019-05-02
[1] => 2019-05-09
[2] => 2019-05-16
[3] => 2019-05-23
[4] => 2019-05-30
[5] => 2019-06-06
[6] => 2019-06-13
[7] => 2019-06-20
[8] => 2019-06-27
[9] => 2019-07-04
[10] => 2019-07-11
[11] => 2019-07-18
[12] => 2019-07-25
[13] => 2019-08-01
[14] => 2019-08-08
[15] => 2019-08-15
[16] => 2019-08-22
[17] => 2019-08-29
[18] => 2019-09-05
[19] => 2019-09-12
[20] => 2019-09-19
[21] => 2019-09-26
)
Current code is:
function getCompDates($y, $m) {
$allDates = [];
$current = strtotime("first thursday of $y-$m");
$end = strtotime("last day of $y-$m");
while ($current <= $end) {
$allDates[] = date('Y-m-d', $current);
$current = strtotime('next thursday', $current);
}
return $allDates;
}
$thursdays = [];
$thursdays_tmp = [];
for ($i = 5; $i <= 9; $i++) {
$thursdays_tmp[] = getCompDates(2019, sprintf('%02d', $i));
print_r($thursdays_tmp);
}
I really just want the $thursday array to be my result. I have added the $thursday_tmp variable for "inner" loop processing, which then finally combines back into $thursday
However, by the final run of the loop, the $thursday_tmp array looks like:
Array
(
[0] => Array
(
[0] => 2019-05-02
[1] => 2019-05-09
[2] => 2019-05-16
[3] => 2019-05-23
[4] => 2019-05-30
)
[1] => Array
(
[0] => 2019-06-06
[1] => 2019-06-13
[2] => 2019-06-20
[3] => 2019-06-27
)
[2] => Array
(
[0] => 2019-07-04
[1] => 2019-07-11
[2] => 2019-07-18
[3] => 2019-07-25
)
[3] => Array
(
[0] => 2019-08-01
[1] => 2019-08-08
[2] => 2019-08-15
[3] => 2019-08-22
[4] => 2019-08-29
)
[4] => Array
(
[0] => 2019-09-05
[1] => 2019-09-12
[2] => 2019-09-19
[3] => 2019-09-26
)
)
You were close, just change this code at the for loop to merge all the arrays into just one:
for ($i = 5; $i <= 9; $i++) {
$thursdays_tmp = array_merge($thursdays_tmp, getCompDates(2019, sprintf('%02d', $i)));
}
print_r($thursdays_tmp);
The complete code can be seen and run here: http://sandbox.onlinephpfunctions.com/code/11439d56c14229acf23ad57a07f71aa88f944040

Php Array to Table Rows

I have some form values in an array, and need to get them into table rows and could use some guidance/help. Below is what I have and am not sure if I am on the right path or not:
//These are my form values
$part = $_POST['part'];
$rel = $_POST['rel'];
$chart = $_POST['chart'];
$dob = $_POST['dob'];
$age = $_POST['age'];
$gender = $_POST['gender'];
//If participant (part) is not empty, start building the table
if ($part != "") {
//The table header (not worried about <td>/<th> semantics right now
$participants = "Participants<table border='1'>
<tr><td>Name</td><td>Relationship</td><td>Chart #</td><td>DOB</td> <td>Age</td><td>Gender</td></tr>";
//This is where I am lost...looping over and outputting on a row by row basis
foreach($part as $row) {
$participants_table = "<tr><td>". $part . "</td><td>". $rel ."</td><td>". $chart ."</td><td>". $dob ."</td><td>". $age ."</td><td>". $gender ."</td></tr>";
}
} else {
//If there are no names in the participant column(s), display the following
$participants = "No Other Participants";
$participants_table = "";
}
//Output from print_r
Next, the following may be overkill, but here goes: Array ( [0] => Christine Eubanks [1] => Ariel Eubanks [2] => Synthia Clow [3] => [4] => [5] => [6] => ) Array ( [0] => Wife [1] => Daughter [2] => Daughter [3] => [4] => [5] => [6] => ) Array ( [0] => 123456 [1] => 654321 [2] => 543210 [3] => [4] => [5] => [6] => ) Array ( [0] => 04/03/1974 [1] => 07/21/2004 [2] => 12/28/1995 [3] => [4] => [5] => [6] => ) Array ( [0] => 44 [1] => 14 [2] => 22 [3] => [4] => [5] => [6] => ) Array ( [0] => F [1] => F [2] => F [3] => [4] => [5] => [6] => ) Array ( [0] => Christine Eubanks [1] => Ariel Eubanks [2] => Synthia Clow [3] => [4] => [5] => [6] => ) Array ( [0] => Wife [1] => Daughter [2] => Daughter [3] => [4] => [5] => [6] => ) Array ( [0] => 123456 [1] => 654321 [2] => 543210 [3] => [4] => [5] => [6] => ) Array ( [0] => 04/03/1974 [1] => 07/21/2004 [2] => 12/28/1995 [3] => [4] => [5] => [6] => ) Array ( [0] => 44 [1] => 14 [2] => 22 [3] => [4] => [5] => [6] => ) Array ( [0] => F [1] => F [2] => F [3] => [4] => [5] => [6] => ) Array ( [0] => Christine Eubanks [1] => Ariel Eubanks [2] => Synthia Clow [3] => [4] => [5] => [6] => ) Array ( [0] => Wife [1] => Daughter [2] => Daughter [3] => [4] => [5] => [6] => ) Array ( [0] => 123456 [1] => 654321 [2] => 543210 [3] => [4] => [5] => [6] => ) Array ( [0] => 04/03/1974 [1] => 07/21/2004 [2] => 12/28/1995 [3] => [4] => [5] => [6] => ) Array ( [0] => 44 [1] => 14 [2] => 22 [3] => [4] => [5] => [6] => ) Array ( [0] => F [1] => F [2] => F [3] => [4] => [5] => [6] => ) Array ( [0] => Christine Eubanks [1] => Ariel Eubanks [2] => Synthia Clow [3] => [4] => [5] => [6] => ) Array ( [0] => Wife [1] => Daughter [2] => Daughter [3] => [4] => [5] => [6] => ) Array ( [0] => 123456 [1] => 654321 [2] => 543210 [3] => [4] => [5] => [6] => ) Array ( [0] => 04/03/1974 [1] => 07/21/2004 [2] => 12/28/1995 [3] => [4] => [5] => [6] => ) Array ( [0] => 44 [1] => 14 [2] => 22 [3] => [4] => [5] => [6] => ) Array ( [0] => F [1] => F [2] => F [3] => [4] => [5] => [6] => ) Array ( [0] => Christine Eubanks [1] => Ariel Eubanks [2] => Synthia Clow [3] => [4] => [5] => [6] => ) Array ( [0] => Wife [1] => Daughter [2] => Daughter [3] => [4] => [5] => [6] => ) Array ( [0] => 123456 [1] => 654321 [2] => 543210 [3] => [4] => [5] => [6] => ) Array ( [0] => 04/03/1974 [1] => 07/21/2004 [2] => 12/28/1995 [3] => [4] => [5] => [6] => ) Array ( [0] => 44 [1] => 14 [2] => 22 [3] => [4] => [5] => [6] => ) Array ( [0] => F [1] => F [2] => F [3] => [4] => [5] => [6] => ) Array ( [0] => Christine Eubanks [1] => Ariel Eubanks [2] => Synthia Clow [3] => [4] => [5] => [6] => ) Array ( [0] => Wife [1] => Daughter [2] => Daughter [3] => [4] => [5] => [6] => ) Array ( [0] => 123456 [1] => 654321 [2] => 543210 [3] => [4] => [5] => [6] => ) Array ( [0] => 04/03/1974 [1] => 07/21/2004 [2] => 12/28/1995 [3] => [4] => [5] => [6] => ) Array ( [0] => 44 [1] => 14 [2] => 22 [3] => [4] => [5] => [6] => ) Array ( [0] => F [1] => F [2] => F [3] => [4] => [5] => [6] => ) Array ( [0] => Christine Eubanks [1] => Ariel Eubanks [2] => Synthia Clow [3] => [4] => [5] => [6] => ) Array ( [0] => Wife [1] => Daughter [2] => Daughter [3] => [4] => [5] => [6] => ) Array ( [0] => 123456 [1] => 654321 [2] => 543210 [3] => [4] => [5] => [6] => ) Array ( [0] => 04/03/1974 [1] => 07/21/2004 [2] => 12/28/1995 [3] => [4] => [5] => [6] => ) Array ( [0] => 44 [1] => 14 [2] => 22 [3] => [4] => [5] => [6] => ) Array ( [0] => F [1] => F [2] => F [3] => [4] => [5] => [6] => )
Whatever you used in your print_r is what I'm focusing on here for this solution. So if you did print_r($_POST) then this would work:
I use htmlspecialchars to clean the string to prevent nasty xss injections.
<?php
foreach($_POST as $row) {
$part = htmlspecialchars($row[0], ENT_QUOTES, 'UTF-8');
$rel = htmlspecialchars($row[1], ENT_QUOTES, 'UTF-8');
$chart = htmlspecialchars($row[2], ENT_QUOTES, 'UTF-8');
$dob = htmlspecialchars($row[3], ENT_QUOTES, 'UTF-8');
$age = htmlspecialchars($row[4], ENT_QUOTES, 'UTF-8');
$gender = htmlspecialchars($row[5], ENT_QUOTES, 'UTF-8');
$unkown = htmlspecialchars($row[6], ENT_QUOTES, 'UTF-8'); //your output shows a [6]'th element
$participants_table = "<tr><td>". $part . "</td><td>". $rel ."</td><td>". $chart ."</td><td>". $dob ."</td><td>". $age ."</td><td>". $gender ."</td></tr>";
}
What's most interesting to me is that in your datadump, there's no associative keys, hence why numerical keys are used instead
when ever you are receiving an array you have to loop it using for loop or foreach loop, Since you have assigned values to variables like $part = $_POST['part']; which is not present, it will always throw error. And in your code $part is not an array to loop through.
<?php
//$part = $_POST[];
$part = array(
array('part', 'rel', 'chart', 'dob', 'age', 'gender'),
array('part1', 'rel1', 'chart1', 'dob1', 'age1', 'gender1')
);
if ($part != "") {
//The table header (not worried about <td>/<th> semantics right now
$participants = "Participants<table border='1'><tr><td>Name</td><td>Relationship</td><td>Chart #</td><td>DOB</td> <td>Age</td><td>Gender</td></tr>";
//This is where I am lost...looping over and outputting on a row by row basis
foreach ($part as $value) {
$participants .= "<tr><td>" . $value[0] . "</td><td>" . $value[1] . "</td><td>" . $value[2] . "</td><td>" . $value[3] . "</td><td>" . $value[4] . "</td><td>" . $value[5] . "</td></tr>";
}
$participants .= '</table>';
}
else {
//If there are no names in the participant column(s), display the following
$participants = "No Other Participants";
}
echo $participants;
?>

Get Range of dates from an array

I'm having the following array of dates :
Array
(
[0] => 2016-02-01
[1] => 2016-02-02
[2] => 2016-02-03
[3] => 2016-02-04
[4] => 2016-02-05
[5] => 2016-02-06
[6] => 2016-02-07
[7] => 2016-02-08
[8] => 2016-02-09
[9] => 2016-02-13
[10] => 2016-02-14
[11] => 2016-02-15
[12] => 2016-03-13
[13] => 2016-03-14
[14] => 2016-03-15
[15] => 2016-03-16
[16] => 2016-03-17
[17] => 2016-03-18
[18] => 2016-03-19
[19] => 2016-04-19
[20] => 2016-04-20
[21] => 2016-04-21
[22] => 2016-04-22
)
How can i get the array dates that form a range. Like
Array
(
[0] => 2016-02-01
[1] => 2016-02-02
[2] => 2016-02-03
[3] => 2016-02-04
[4] => 2016-02-05
[5] => 2016-02-06
[6] => 2016-02-07
[7] => 2016-02-08
[8] => 2016-02-09
)
Array
(
[0] => 2016-02-13
[1] => 2016-02-14
[2] => 2016-02-15
)
Array
(
[0] => 2016-03-13
[1] => 2016-03-14
[2] => 2016-03-15
[3] => 2016-03-16
[4] => 2016-03-17
[5] => 2016-03-18
[6] => 2016-03-19
)
The dates in the main array I listed can be of any order. The example I provided all the date ranges can be identifiable. But the raay is dynamic and can have date in random order. All I want to have date ranges out if that array. I'm getting mad of thinking. Please help. Thanks in advance.
You have the following code. Please try this.
$array = Array(0 => '2016-02-01',
1 => '2016-02-02',
2 => '2016-03-19',
3 => '2016-02-04',
4 => '2016-02-05',
5 => '2016-03-18',
6 => '2016-02-07',
7 => '2016-02-08',
8 => '2016-02-09',
9 => '2016-02-13',
10 => '2016-02-14',
11 => '2016-02-15',
12 => '2016-03-13',
13 => '2016-03-14',
14 => '2016-03-15',
15 => '2016-03-16',
16 => '2016-03-17',
17 => '2016-02-06',
18 => '2016-02-03',
19 => '2016-04-19',
20 => '2016-04-20',
21 => '2016-04-21',
22 => '2016-04-22');
//echo "<pre>";print_r($array);
sort($array);
$newDateArray = array();
$i = 0;
$arrayCount = count($array);
foreach($array as $key=>$val) {
//echo $key;
if(isset($array[$key+1])) {
$date1 = $val;
$date2 = $array[$key+1];
$newDateArray[$i][] = $date1;
$datetime1 = date_create($date1);
$datetime2 = date_create($date2);
$interval = date_diff($datetime1, $datetime2);
if($interval->days > 1) {
$i++;
}
}
else if($arrayCount == ($key+1)) {
$newDateArray[$i][] = $date2;
}
}
echo "<pre>";print_r($newDateArray);exit;
your result would be as follows.
Array
(
[0] => Array
(
[0] => 2016-02-01
[1] => 2016-02-02
[2] => 2016-02-03
[3] => 2016-02-04
[4] => 2016-02-05
[5] => 2016-02-06
[6] => 2016-02-07
[7] => 2016-02-08
[8] => 2016-02-09
)
[1] => Array
(
[0] => 2016-02-13
[1] => 2016-02-14
[2] => 2016-02-15
)
[2] => Array
(
[0] => 2016-03-13
[1] => 2016-03-14
[2] => 2016-03-15
[3] => 2016-03-16
[4] => 2016-03-17
[5] => 2016-03-18
[6] => 2016-03-19
)
[3] => Array
(
[0] => 2016-04-19
[1] => 2016-04-20
[2] => 2016-04-21
[3] => 2016-04-22
)
)
Now you can easily split your array. and get the result what you exactly want.
Have a Great Day!!!... Fill free to ask more your doubts...

2 arrays, need the result to be what i show

This is my arrays, i want this result below, but cant figure it out.
The result is a count of how many times an ID have a date between 2014-06-01 to the last day of month 2014-06-xx
In my array with dates "array[1]", only 6-7-8 have wrong dates.
Help please :-S
RESULT
Array
(
[0] => Array
(
[1] => 2
[4] => 2
[7] => 3
[9] => 1
[12] => 1
[13] => 1
)
)
Array
(
[0] => Array
(
[0] => 4
[1] => 4
[2] => 7
[3] => 1
[4] => 7
[5] => 7
[6] => 3
[7] => 3
[8] => 4
[9] => 9
[10] => 12
[11] => 2
[12] => 13
[13] => 1
)
[1] => Array
(
[0] => 2014-06-18
[1] => 2014-06-10
[2] => 2014-06-05
[3] => 2014-06-05
[4] => 2014-06-12
[5] => 2014-06-11
[6] => 2013-12-12
[7] => 2014-07-23
[8] => 2014-05-13
[9] => 2014-06-01
[10] => 2014-06-12
[11] => 2014-06-04
[12] => 2014-06-04
[13] => 2014-06-11
)
)
Hope the following works. Did not test it.
$idsArray = $yourArray[0];
$dateArray = $yourArray[1];
$countArray = array(); // the result array
$beginningTimestamp = strtotime('2014-06-01');
$lastTimestamp = strtotime('2014-07-01'); // before the first of July comes the last of June
foreach ($idsArray as $key => $id) {
if (isset($dateArray[$key])) {
$timestamp = strtotime($dateArray[$key];
if ($timestamp >= $beginningTimestamp && $timestamp < $lastTimestamp) {
if (isset($countArray[$id])) {
$countArray[$id]++;
} else {
$countArray[$id] = 1;
}
}
}
}

Categories