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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.