Jump to content

[SOLVED] Loop


ballhogjoni

Recommended Posts

Since you are looking for a sigma of something why not do a 
[code
<?php
for($i =1; $i <=$num_days; $i++){
$value[$i] = //Some math stuff;
}
$sum = array_sum($value);
?>

 

Or you can view a a day to day of it etc etc,  you might want to might need to try this below however, since you will need compounding interest

<?php
for($i =1; $i <=$num_days; $i++){
if($i >1){
$j = $i-1;
$value[$i] = //Some math stuff using the recursive value;
}
else{
$value[$i] = //Some math based ont he IV
}
}
?>

 

Like so,

Link to comment
https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353033
Share on other sites

if I had 365 days and I wanted to have the script print each day, 1,2,3,4...

 

what type of loop would that be? I have used a foreach() & for() and they didn't work.

 

My code

<?php
$y=5;
$days = ($y*365);
$resultDay = array($days);

for($i=1; $i<=$days; $i++){
$years=$days-1;
}
echo $years;
?>

 

Outputs:

 

1824

 

Shouldn't it output 1,2,3,4,5,.....1825?

Link to comment
https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353536
Share on other sites

Ok great, thanks. The problem now is that it is just repeating 182418241824...

 

It should be saying

 

1

2

3

4

5

6

7

etc

 

Maybe I am not explaining it well enough...this is what I want the code to do:

 

foreach() day run this code...if there are 365 days this code should run 365 times and I want it to output something 365 times, I.E.

 

foreach($day as $dy) {

//some code

echo 'somthing';

}

 

Output should look something like this:

 

1

2

3

4

5

6

etc

Link to comment
https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353552
Share on other sites

Sorry no intermediaries on this one... (play with n for that!)

/*
Daily Compounded Interest
V = D(1 + r/365)365n
D is the amount deposited, r is the interest rate,
n is the number of years, and V is the final amount.
*/
function dci($d, $r, $n)
{
return $d*( pow((1+$r/365), 365*$n) );
}
echo "dci: ".dci(10, 2, 3);

ref: http://www.math.umd.edu/~rll/cgi-bin/finance.cgi

Link to comment
https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353593
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.