Hi,
It’s been a while since doing any PHP code, so I’m a bit rusty. I need to create a multi-dimensional array that contains:
- Date
- Description
- Amount
The array will be added to, several times. That is, once for a number of 14 day intervals, monthly intervals, 5 weekly intervals, etc,etc
So, I need the PHP code setup so that I can simply parse it the ‘start date’, ‘end date’ and the interval number of days (7,14,etc)
Once this array is built, it then needs to be sorted to date and description order. Then some code to go through the array and create a CSV file, which is later used in a spreadsheet.
I have been using this code …
<?php
date_default_timezone_set('Australia/Melbourne');
$startDate = "2014-07-01";
$endDate = "2015-06-30";
$daysBetween = 14;
$finalResult = array();
function addDayswithdate($date,$days, $endDate, &$finalResult){
$tempDate = strtotime($date);
$tempDate += 3600*24*$days;
if ($tempDate < strtotime($endDate)) {
$finalResult[] = date("Y-m-d", $tempDate);
addDayswithdate(date("Y-m-d", $tempDate), $days, $endDate, $finalResult);
} else {
return true;
}
}
addDayswithdate($startDate,$daysBetween, $endDate, $finalResult);
print_r($finalResult);
?>
and the output is …
Array
(
[0] => 2014-07-15
[1] => 2014-07-29
[2] => 2014-08-12
[3] => 2014-08-26
[4] => 2014-09-09
[5] => 2014-09-23
[6] => 2014-10-07
[7] => 2014-10-21
[8] => 2014-11-04
[9] => 2014-11-18
[10] => 2014-12-02
[11] => 2014-12-16
[12] => 2014-12-30
[13] => 2015-01-13
[14] => 2015-01-27
[15] => 2015-02-10
[16] => 2015-02-24
[17] => 2015-03-10
[18] => 2015-03-24
[19] => 2015-04-06
[20] => 2015-04-20
[21] => 2015-05-04
[22] => 2015-05-18
[23] => 2015-06-01
[24] => 2015-06-15
[25] => 2015-06-29
)
so, this only creates the date. I need to extend it to include the “Description” and the “Amount”. I’m not entirely sure how to extend the array to be a multi-dimensional array. Also, in the code above, I don’t understand why the function calls itself ?
Once I have the multi-dimasional array sorted out, and how to reference each key/index and value, then I should be okay to extend it for the other iterations. I see there are some easy examples at http://php.net/manual/en/function.fputcsv.php for writing an array to a CSV file.
If someone can assist please.