I have an array of dates and values, for example:
$dates = ['2014-12-01', '2014-12-02', '2014-12-08', '2014-12-09', '2014-12-10', '2014-12-11'];
$values = [5, 3, 7, 8, 9, 2];
You'll note that 12/01 is a Monday, as is 12/08. I'd like to group data from these two arrays by day if the week:
[
'monday' => [5, 7],
'tuesday' => [3, 8],
'wednesday' => [0, 9],
'thursday' => [0, 2],
]
You'll note that the arrays are formed by grabbing the values associated with the days of the week. However, in the case that a Wednesday date exists, for example, but the prior Tuesday does not, then the array should have a "0". In other words, the 4 arrays should all be the same length.
NOTE: So far, I have only determined how to find the day of the week from a date: date('l', strtotime("2014-12-08")); I really can't figure out the general algorithm to solve this.
datearray. For each date's key/value, determine the day of the week. Add the value for the same key from thevaluesarray to an array with a key that corresponds to the day of the week.$weekdays[$day_of_week][]=$values[$dates_key];I'm sorry, I don't want to write all the code -- nothing personal. But the SO community will help to troubleshoot your code if you make an attempt and have trouble.