Dear all,
Kindly help with this code I have written, it is not returning the array I created. It is a very small script but I have been looking for a very long time but I couldn't see why it went wrong.
$duration = 2;
$start='01-01-2019';
$month =date('n', strtotime($start));
$year =date('Y', strtotime($start));
$mon = 12-$month+1;
$remainingMonth = $duration*12;
$years_arr = array("$year");
$residue_arr = array("$remainingMonth");
$years_arr = process($remainingMonth,$year,$mon,$years_arr,$residue_arr);
print_r($years_arr); //<output
function process($remainingMonth,$year,$mon,$years_arr,$residue_arr){
$residue = $remainingMonth - $mon;//$D$18-D20
if($residue != 0){
$new_year = $year+1;
array_push($years_arr, $new_year);
array_push($residue_arr, $residue);
if($residue > 12 ){
$mon = 12;
} else {
$mon = $residue;
}
echo "<br>";
process($residue,$new_year,$mon,$years_arr,$residue_arr);
} else {
print_r($years_arr);
return $years_arr;
}
}//end of process(..)
The objective is to add a year to the $years_arr array and then print it put, yet I notice that nothing get's printed out. Please assist, if you need more info from my side, please do ask. Thank you very much in advance.