Ah, I see it. The value that's 10 years old needs to be divided by the rate 10 times. Or (1+rate)^10
If you do this
$npv = ($values[$year - $i] + $npv) / (1 + $rate);
then it should work, since you are already running backward through the array.

By the way, I would do the for loop like this, but it either way is the same.
for ($i=$year;$i>=0;$i-=1) {
$npv = ($values[$i] + $npv) / (1 + $rate);
}

Actually, if array[0] is the capital outlay, shouldn't you run through starting at 0 and going to $year?

Are you ready to take your data science career to the next step, or break into data science? With Springboardâ€™s Data Science Career Track, youâ€™ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

In your code is $rate 8.15 or .0815? It needs to be .0815; if it isn't use $rate/100.
Also, you should not be dividing by (1+$rate) you should multiply by (1-$rate).
If I understand the question correctly, that should be all you need to get it working right.

Er... That last line might not make sense. I don't know NPV that well, I'm just good at figuring formulas out. Doing it the way I suggested matched Excel perfectly.

If you do this

$npv = ($values[$year - $i] + $npv) / (1 + $rate);

then it should work, since you are already running backward through the array.

By the way, I would do the for loop like this, but it either way is the same.

for ($i=$year;$i>=0;$i-=1) {

$npv = ($values[$i] + $npv) / (1 + $rate);

}

Actually, if array[0] is the capital outlay, shouldn't you run through starting at 0 and going to $year?