I am trying to create an amortization calculator that calculates the declining principal
$x = 1;
$starting_pmt = 26;
$ending_pmt = 36;
$i = 0.0010316264327892;
$p = 410000;
$pmt = 916.84;
$num_pmts = $ending_pmt - $starting_pmt;
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>PMT Num</th>";
echo "<th>Balance</th>";
echo "<th>Principle</th>";
echo "<th>TTL Principle</th>";
echo "<th>Interest</th>";
echo "<th>Payment</th>";
echo "</tr>";
while ( $starting_pmt <= $ending_pmt ) {
echo "<tr><td>";
echo $starting_pmt;
echo "</td><td>";
echo $p;
echo "</td>";
echo "<td>$prin</td>";
echo "<td>$TTLprin</td>";
echo "<td>$interest</td>";
echo "<td>$TTLPmt</td> </tr>";
$starting_pmt = $starting_pmt + 1;
$p = $p -($p*$i);
$prin = $pmt - ($p * $i);
$interest = $pmt - $prin;
$TTLPmt = $prin + $interest;
//$cumTTL = $$pmt - ($p * $i);
$TTLprin = $prin + $prin;
}
echo "</table>";
?>
balance for each payment and the total principle paid between two values. I also want to calculate the interested paid for each payment and the accumulative interest paid between the two values.
This is what I am starting with.
I cannot figure out how to get the loop to do the math during each iteration............... I have been working my original code and I am getting closer. I cannot get the loop to calculate the cumulative total for principal and interest paid.
<?php
$starting_pmt = 1;
$ending_pmt = 10;
$i = 0.0010316264327892;
$p = 410000;
$pmt = 916.84;
$num_pmts = $ending_pmt - $starting_pmt;
while($x < $num_pmts) {
echo "<tr>";
echo "<td>$x</td>";
echo "<td>".$p - ($p*$i)."</td>";
echo "<td></td>";
echo "<td></td>";
echo "<tr>";
$x++;
I get the math. It's getting the while loop to do what I need. It's not calculating the cumulative total for the principle paid.
Here is a way to make an amortization script, you need to pass back what you want your rate, payment date, and all that good stuff. then I am returning an associative array with all the values for each month.
public static function amortizeLoan($principal, $rate, $term, $extra_days, $payment_date){
$payment = self::getPayment($principal,($rate*100),$term,$extra_days);
$MonthlyInterestRate = $rate / 12;
$Multiplier = 1 + $MonthlyInterestRate;
$TermRate = 1;
for($x=0;$x<$term;$x++){
$TermRate = $TermRate * $Multiplier;
}
$Days = $extra_days - 30;
$oddDayInt = $Days > 0 ? round($principal * ($rate / 365.25) * $Days,2) : 0;
$amortization = [];
$total_interest = 0;
$total_principal = 0;
$remaining_principal = $principal;
$compareDay = date('d', strtotime($payment_date));
for($x=0;$x<$term;$x++){
$this_int_paid = round((($rate)/12) * $remaining_principal,2);
if($x==0){$this_int_paid += $oddDayInt;}
$this_princ_paid = round($payment - $this_int_paid,2);
$this_rem_princ = round($remaining_principal - $this_princ_paid,2);
if($x == ($term-1)){
if($this_rem_princ < 0){
$this_princ_paid-=abs($this_rem_princ);
$payment=round($this_int_paid+$this_princ_paid,2);
}else{
$this_princ_paid+=$this_rem_princ;
$payment=round($this_int_paid+$this_princ_paid,2);
}
}
$remaining_principal -= $this_princ_paid;
$total_interest += $this_int_paid;
$total_principal += $this_princ_paid;
// *** If month days < payment date, payment date falls on the last day of that month.***
$nextMonth = strtotime("last day of next month", strtotime($payment_date));
$lastDayNextMonth = date('d', $nextMonth);
if ($compareDay >= $lastDayNextMonth) {
$payment_date_time = $x ? $nextMonth : strtotime($payment_date);
} else {
$payment_date_time = $x ? strtotime("+1 month", strtotime($payment_date)) : strtotime($payment_date);
}
if ($lastDayNextMonth > date('d', strtotime($payment_date)) && date('t', strtotime($payment_date)) < $compareDay) {
$date = date('Y-m-d', $nextMonth);
$newDate = date_create($date);
$newDate->format('Y-m-d');
$finalDate = date_date_set(
$newDate,
date_format($newDate, 'Y'),
date_format($newDate, 'm'),
$compareDay
);
$formatedDate = $finalDate->format('m/d/y');
$payment_date_time = strtotime($formatedDate);
}
$payment_date = gmdate("Y-m-d", $payment_date_time);
$amortization[] = [
"payment"=>($x+1),
"amount"=>$payment,
"principal"=>$this_princ_paid,
"interest"=>$this_int_paid,
"total_principal"=>$total_principal,
"total_interest"=>$total_interest,
"remaining_balance"=>round($remaining_principal,2),
"payment_date"=>$payment_date
];
}
return $amortization;
}
Related
I'm creating a calendar with Sunday being the start of each week and I want to present the week number of the year before each row of dates.
This is my calendar
my calendar
How can I add week numbers like this:
This is what I need
My code:
<?php
function generate_calendar($month, $year) {
$calendar = array();
$days_in_month = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$first_day_of_month = date('w', strtotime("$year-$month-01"));
$week_number = 1;
$week = array();
// Determine the week number offset
$days_from_january_1st = strtotime("$year-01-01");
$days_to_first_day_of_month = strtotime("$year-$month-01");
$week_number_offset = floor(($days_to_first_day_of_month - $days_from_january_1st) / 604800);
// Check if the last week of the previous month is full (7 days)
$last_week_of_previous_month = $week_number_offset;
if ($month > 1) {
$previous_month = $month - 1;
$previous_month_year = $year;
$previous_month_year = date("Y", strtotime("-1 month" , strtotime("$year-$month-01")));
$previous_month = date("n", strtotime("-1 month" , strtotime("$year-$month-01")));
if ($previous_month == 0) {
$previous_month = 12;
$previous_month_year = $year - 1;
}
$days_in_previous_month = cal_days_in_month(CAL_GREGORIAN, $previous_month, $previous_month_year);
$last_day_of_previous_month = date('w', strtotime("$previous_month_year-$previous_month-$days_in_previous_month"));
if ($last_day_of_previous_month == 6) {
$last_week_of_previous_month=$last_week_of_previous_month + 1;
} else {
// Check if the last week of the previous month only has a few days
$last_week_of_previous_month = $last_week_of_previous_month;
}
}
// Generate the previous month's days
for ($i = 1; $i <= $first_day_of_month; $i++) {
array_unshift($week, "");
}
// Generate the current month's days
for ($i = 1; $i <= $days_in_month; $i++) {
$week[] = $i;
if (count($week) == 7) {
$calendar[$week_number + $last_week_of_previous_month] = $week;
$week_number++;
$week = array();
}
}
// Generate the next month's days
$remaining_days = 7 - count($week);
for ($i = 1; $i <= $remaining_days; $i++) {
$week[] = '';
}
if (!empty($week)) {
$calendar[$week_number + $last_week_of_previous_month] = $week;
}
return $calendar;
}
$year = 2022;
echo "<table>\n";
echo " <tr>\n";
echo " <th colspan='3'>$year</th>\n";
echo " </tr>\n";
echo " <tr>\n";
for($i=1; $i<=12; $i++){
$month_name = date('F Y', strtotime("$year-$i-01"));
$calendar = generate_calendar($i, $year);
echo "<td>\n";
echo "<table>\n";
echo " <tr>\n";
echo " <th colspan='8'>$month_name</th>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <th>Week</th>\n";
echo " <th>Sun</th>\n";
echo " <th>Mon</th>\n";
echo " <th>Tue</th>\n";
echo " <th>Wed</th>\n";
echo " <th>Thu</th>\n";
echo " <th>Fri</th>\n";
echo " <th>Sat</th>\n";
echo " </tr>\n";
foreach ($calendar as $week_number => $week) {
echo " <tr>\n";
echo " <td>$week_number</td>\n";
foreach ($week as $day) {
if (empty($day)) {
echo " <td></td>\n";
} else {
echo " <td>$day</td>\n";
}
}
echo " </tr>\n";
}
echo "</table>\n";
echo "</td>\n";
if($i==3 || $i==6 || $i==9){
echo " </tr>\n";
echo " <tr>\n";
}
}
echo " </tr>\n";
echo "</table>\n";
?>
Trying to add week number which counts from first week of January (if last week of previous month is not full 7 days then first week of current month start from last week of previous month), but my code only count from first week of current month.
I managed to get the right result (as far as I tested) with IntlCalendar and its FIELD_WEEK_OF_YEAR constant instead of counting Sundays.
I did some refactoring of your function, but ran out of time to do a full reduction of the script (there may still be lines that can be simplified/condensed).
Code: (Demo)
function generate_calendar(int $month, int $year) {
$calendar = [];
$week_number = (IntlCalendar::fromDateTime ("$year-$month-01"))->get(IntlCalendar::FIELD_WEEK_OF_YEAR);
$month_start = new DateTime("$year-$month-01");
// Generate the previous month's days
if ($first_day = $month_start->format('w')) {
$week = array_fill(1, $first_day, '');
}
// Generate the current month's days
$days_in_month = $month_start->format('t');
for ($i = 1; $i <= $days_in_month; $i++) {
$week[] = $i;
if (count($week) == 7) {
$calendar[$week_number] = $week;
$week_number++;
$week = [];
}
}
if ($week) {
// Generate empty days for the next month
$calendar[$week_number] = array_pad($week, 7, '');
}
return $calendar;
}
I don't believe there is any way to set the start day of the week in the standard library of PHP without manual calculation, but you can do it easily with the intl library (make sure the intl PHP extension is enabled):
$cal = IntlGregorianCalendar::createInstance();
// Set start of week to Sunday
$cal->setFirstDayOfWeek(IntlGregorianCalendar::DOW_SUNDAY);
// Get week number of the year for the current date
$weekOfYear = intval(IntlDateFormatter::formatObject($cal, 'w'));
// Advance to the next week
$cal->add(IntlGregorianCalendar::FIELD_WEEK_OF_YEAR, 1);
// ect...
I have a issue with the return of my multidimensional arrays. For some reason two of them are returned as objects and not arrays when the initialization is fairly the same.
I'm creating a time card and would like to return the % of time an employee was late and on time in a month for the total of past 12 months.
Code:
$eID = $_GET['showLatencyValues'];
//get the last 12 months
$month = time();
for ($i = 1; $i <= 12; $i++) {
$month = strtotime( date( 'Y-m-01' )." -$i months");
$months[] = date("r", $month);
}
$ii = 0;
for($i = 11; $i >= 0; $i--) {
$m = explode(" ", $months[$i]);
$result = $m[2].'. '.$m[3];
$last12months[$ii][0] = $ii;
$last12months[$ii][1] = $result;
$ii++;
}
//set the correct dates
$f = explode(" ", $last12months[0][1]);
$t = explode(" ", $last12months[11][1]);
$from = $f[1].'-'.letterToNumeric($f[0]).'-01';
$days = cal_days_in_month(CAL_GREGORIAN, letterToNumeric($t[0]), $t[1]); // 31
$to = $t[1].'-'.letterToNumeric($t[0]).'-'.$days;
//get the information from database
$sql = mysqli_query($conn, "SELECT DISTINCT `timeIn`,`date` FROM `clock` WHERE `eID`='$eID' AND date BETWEEN '$from' AND '$to'");
$res = mysqli_fetch_array($sql);
$break = explode("-", $res['date']);
$month = $break[1]; //set current month to
$countMonth = 0; //month number
$count = 0; //day number
$sql = mysqli_query($conn, "SELECT min(timeIn) as timeIn,`date` FROM `clock` WHERE `eID`='$eID' AND date BETWEEN '$from' AND '$to' group by date");
while($res = mysqli_fetch_array($sql)) {
$break = explode("-", $res['date']); //get the current selected month
if($month != $break[1]) { //check if current month is the same as selected by database if not then
$countMonth++; //add current month number
$count = 0; //set current day number to 0
$month = $break[1]; //set the current month to whatever is selected by database
}
$timeInData[$countMonth][$count] = $res['timeIn'];
$count++;
}
$count = 0;
for($i = 0; $i < count($timeInData); $i++) {
for($s = 0; $s < count($timeInData[$i]); $s++) {
$firstShift_timeIn = setting($conn, 'timeIn1');
$secondShift_timeIn = setting($conn, 'timeIn2');
$lateConsideredAfter = setting($conn, 'lateAfter');
$actualTime = date("H:i", strtotime($timeInData[$i][$s]));
if($res_shift['shift'] == 1) $considerLateTime = date("H:i", strtotime($firstShift_timeIn." +".$lateConsideredAfter." minutes"));
else $considerLateTime = date("H:i", strtotime($secondShift_timeIn." +".$lateConsideredAfter." minutes"));
if($actualTime > $considerLateTime) $late[$count]++;
else $onTime[$count]++;
}
$count++;
}
if($count != 12) {
$amt = (12-($count))-1;
for($w = 0; $w <= $amt; $w++) {
$onTimeYesData[$w][0] = $w;
$onTimeYesData[$w][1] = 0;
$onTimeNoData[$w][0] = $w;
$onTimeNoData[$w][1] = 0;
}
}
for($q = ($amt+1); $q <= 11; $q++) {
$total = $onTime[($q-($amt+1))] + $late[($q-($amt+1))];
$onTimeYesData[$q][0] = $q;
$onTimeYesData[$q][1] = round(($onTime[($q-($amt+1))]/$total)*100);
$onTimeNoData[$q][0] = $q;
$onTimeNoData[$q][1] = round(($late[($q-($amt+1))]/$total)*100);
}
$response[1] = $last12months;
$response[0] = $onTimeYesData;
$response[2] = $onTimeNoData;
echo json_encode($response[1])."\n\n".json_encode($response[0])."\n\n".json_encode($response[2]);
Output that I receive:
[[0,"Mar. 2019"],[1,"Apr. 2019"],[2,"May. 2019"],[3,"Jun.
2019"],[4,"Jul. 2019"],[5,"Aug. 2019"],[6,"Sep. 2019"],[7,"Oct.
2019"],[8,"Nov. 2019"],[9,"Dec. 2019"],[10,"Jan. 2020"],[11,"Feb.
2020"]]
{"1":[1,90],"2":[2,100],"3":[3,96],"4":[4,91],"5":[5,95],"6":[6,95],"7":[7,100],"8":[8,92],"9":[9,95],"10":[10,89],"11":[11,88]}
{"1":[1,10],"2":[2,0],"3":[3,4],"4":[4,9],"5":[5,5],"6":[6,5],"7":[7,0],"8":[8,8],"9":[9,5],"10":[10,11],"11":[11,13]}
I expect the two other outputs to be in the same format as the first one.
Any help is very much appreciated. Thanks.
I'm trying to display dates in a HTML table. I want to display each month, but I failed when the dates go over a month for example: 2015-30-11 to 2015-01-12
They break the table because there are too many <td>'s and I don't know how to display them in the next month.
Each user Has their own dates.
Code:
$month = date(m);
$year = date(Y);
$day = date(d);
if (isset($_GET['month'])) {
$month = $_GET['month'];
}
$days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
echo "<h2>$month-$day-$year</h2>";
echo "<h3>Amount of days: $days </h3>";
$days = $days + 1;
$employee_count = 0;
$sql = "SELECT * FROM employee WHERE inactive = 0";
$result = mysqli_query($con, $sql) or die ('Unable to execute query. ' . mysqli_error($con));
while ($row = mysqli_fetch_assoc($result)) {
$employee_id[] = $row;
$employee_count++;
}
echo "<table border='1'>";
echo "<tablehead>";
echo "<tr>";
for ($j = 0; $j < $days; $j++) {
echo "<th>$j</th>";
}
echo "</tr>";
echo "</tablehead>";
for ($i = 0; $i < $employee_count; $i++) {
echo "<tr>";
$id = $employee_id[$i]['employee_ID'];
$sql = "select * from employee where inactive = 0 and employee_ID = $id";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$employee[] = $row;
}
$name = $employee[0]['name'];
$surname = $employee[0]['surname'];
echo "<td>$surname $name</td>";
$count_absences = 0;
$sql = "select * from absences where employee_FK = $id";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$absences[] = $row;
$count_absences++;
}
$table = $days - 1;
$minus = 0;
for ($l = 0; $l < $table; $l++) {
for ($y = 0; $y < $count_absences; $y++) {
$start = $absences[$y]['start'];
$end = $absences[$y]['end'];
$dStart = new DateTime($start);
$dEnd = new DateTime($end);
$dDiff = $dStart->diff($dEnd);
$diff = $dDiff->days;
$diff = $diff + 1;
$date = $start;
$start_day = date('d', strtotime($date));
$start_day = $start_day - 1;
$start_month = date('m', strtotime($date));
$start_day = $start_day - 1;
if ($start_month == $month && $start_day == $l) {
for ($a = 0; $a < $diff; $a++) {
echo "<td>X</td>";
$l++;
}
}
}
echo "<td></td>";
unset($employee);
}
echo "</tr>";
unset($absences);
}
echo "</table>";
if ($month == 12) {
$next = 1;
} else {
$next = $month + 1;
}
if ($month == 1) {
$previous = 12;
} else {
$previous = $month - 1;
}
echo "<br>";
echo "<button type=\"button\" name=\"previous\" >Previous</button>";
echo "<button type=\"button\" name=\"next\" >Next</button>";
Revise your inner loop like this:
for($l=0;$l<$table;$l++){
$mark = false;
for($y=0; $y<$count_absences; $y++){
$start = $absences[$y]['start'];
$end = $absences[$y]['end'];
$dStart = new DateTime($start);
$dEnd = new DateTime($end);
$dDiff = $dStart->diff($dEnd);
$diff = $dDiff->days + 1;
$start_day = date('d', strtotime($start)) - 1;
$start_month = date('m', strtotime($start));
$lString = $year.'-'.$month.'-'.($l+1);
$lDate = new DateTime($lString);
if($lDate>=$dStart && $lDate<=$dEnd){
$mark = true;
break;
}
}
if($mark){
echo "<td>X</td>";
} else {
echo "<td></td>";
}
unset($employee);
}
That way on each iteration the specific day we're on for the employee will be checked against all date spans of their absence, even if absence spans across months.
I add this snippet:
if ($start_month != $month) {
echo '</tr><tr>';
}
It might be all you need, but I am not sure if that is going to work.
In any case you need to check if you are in a different month to switch to next line. I am not sure where that would be in your code.
<?
$month = date(m);
$year = date(Y);
$day = date(d);
if (isset($_GET['month'])) {
$month = $_GET['month'];
}
$days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
echo "<h2>$month-$day-$year</h2>";
echo "<h3>Amount of days: $days </h3>";
$days = $days + 1;
$employee_count = 0;
$sql = "SELECT * FROM employee WHERE inactive = 0";
$result = mysqli_query($con, $sql) or die ('Unable to execute query. ' . mysqli_error($con));
while ($row = mysqli_fetch_assoc($result)) {
$employee_id[] = $row;
$employee_count++;
}
echo "<table border='1'>";
echo "<tablehead>";
echo "<tr>";
for ($j = 0; $j < $days; $j++) {
echo "<th>$j</th>";
}
echo "</tr>";
echo "</tablehead>";
for ($i = 0; $i < $employee_count; $i++) {
echo "<tr>";
$id = $employee_id[$i]['employee_ID'];
$sql = "select * from employee where inactive = 0 and employee_ID = $id";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$employee[] = $row;
}
$name = $employee[0]['name'];
$surname = $employee[0]['surname'];
echo "<td>$surname $name</td>";
$count_absences = 0;
$sql = "select * from absences where employee_FK = $id";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$absences[] = $row;
$count_absences++;
}
$table = $days - 1;
$minus = 0;
for ($l = 0; $l < $table; $l++) {
for ($y = 0; $y < $count_absences; $y++) {
$start = $absences[$y]['start'];
$end = $absences[$y]['end'];
$dStart = new DateTime($start);
$dEnd = new DateTime($end);
$dDiff = $dStart->diff($dEnd);
$diff = $dDiff->days;
$diff = $diff + 1;
$date = $start;
$start_day = date('d', strtotime($date));
$start_day = $start_day - 1;
$start_month = date('m', strtotime($date));
$start_day = $start_day - 1;
if ($start_month != $month) {
echo '</tr><tr>';
}
if ($start_month == $month && $start_day == $l) {
for ($a = 0; $a < $diff; $a++) {
echo "<td>X</td>";
$l++;
}
}
}
echo "<td></td>";
unset($employee);
}
echo "</tr>";
unset($absences);
}
echo "</table>";
if ($month == 12) {
$next = 1;
} else {
$next = $month + 1;
}
if ($month == 1) {
$previous = 12;
} else {
$previous = $month - 1;
}
echo "<br>";
echo "<button type=\"button\" name=\"previous\" >Previous</button>";
echo "<button type=\"button\" name=\"next\" >Next</button>";
Maybe you should check in your loop that month of current date (in loop) is the same as month of previous date by keeping at the end of every loop the last value of month ($actualMonth). You probably have to setup this value outside the loop with null and ignore this verification if $actualMonth is null. Also, you can start verification after first loop.
If it's different, you have to break your loop. You can compare directly with your $month parameter.
OR
You could restrict your SQL query to get absence only for the month currently displayed.
MySQL :
SELECT * FROM employees WHERE MONTH(date_to_checked) = month_number;
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_month
I'm currenty looking into this tutorial to create a calendar. The only problem I have atm is that my months are in english instead of dutch. How can I change the output of 'july' to 'juli' ?
<?php
$vandaag = date("d"); // Current day
$maand = date("m"); // Current month
$jaar = date("Y"); // Current year
$dagen = cal_days_in_month(CAL_GREGORIAN,$maand,$jaar); // Days in current month
$vorigemaand = date("t", mktime(0,0,0,$maand-1,1,$jaar)); // Days in previous month
$begin = date("N", mktime(0,0,0,$maand,1,$jaar)); // Starting day of current month
$einde = date("N", mktime(0,0,0,$maand,$dagen,$jaar)); // Finishing day of current month
$vorigestart = $begin - 1; // Days of previous month in calander
$counter = 1;
$volgendeMaandCounter = 1;
if($begin > 5){ $rows = 6; }else {$rows = 5; }
for($i = 1; $i <= $rows; $i++){
echo '<tr class="week">';
for($x = 1; $x <= 7; $x++){
if(($counter - $begin) < 0){
$date = (($vorigemaand - $vorigestart) + $counter);
$class = 'class="blur"';
}else if(($counter - $begin) >= $dagen){
$date = ($volgendeMaandCounter);
$volgendeMaandCounter++;
$class = 'class="blur"';
}else {
$date = ($counter - $begin + 1);
if($vandaag == $counter - $begin + 1){
$class = 'class="today"';
}
}
echo '<td '.$class.'><a class="date">'. $date . '</a></td>';
$counter++;
$class = '';
}
echo '</tr>';
}
?>
Thanks in advance!
try with this code:
setlocale(LC_TIME, 'de_DE', 'deu_deu');
/* print test date string */
echo strftime("%A, %d. %B %Y");
I have:
for ($i=0; $i < 10; $i++) {
$date = Date('Y-m-d', strtotime("-$i days"));
$numar = $this->Misc->get($date);
// here a want to add to a array $date and $number
}
When using a foreach loop on the array i want to get:
Date : X Number : Y
Date : X1 Number : Y1
Date : X2 Number : Y2
$arr_outupt = array();
for ($i=0; $i < 10; $i++) {
$date = Date('Y-m-d', strtotime("-$i days"));
$numar = $this->Misc->get($date);
$arr_output[] = array("date"=>$date, "number"=>$numar);
}
echo "<table>";
foreach($arr_output as $arr_temp)
{
echo "<tr>";
echo "<td>Date : </td>";
echo "<td>".$arr_temp['date']."</td>";
echo "<td>Number : </td>";
echo "<td>".$arr_temp['number']."</td>";
echo "</tr>";
}
echo "</table>";
Try this its quite simple
$new_array = array();
for ($i=0; $i < 10; $i++) {
$date = Date('Y-m-d', strtotime("-$i days"));
$numar = $this->Misc->get($date);
// here a want to add to a array $date and $number
$new_array[] = array('Date' => $date, 'Number' => $numar );
}