Assume that your data are stored in an array like this

$seq = array(0=>-100, 1=>40, 2=>59, 3=>55);

$period_to_solve = 4;

$rate = 0.15;

//First sum everything up

for ($x=0; $x<$period_to_solve; $x++)

{

$sum += $seq[$x] * pow($rate + 1, $x);

}

// NPV = {sum} + x/(1+rate)^4

// -{sum} * (1+rate)^4 = x

$final_period = 0 - $sum * pow(1+$rate,$period_to_sol